summaryrefslogtreecommitdiff
path: root/internal/cache
diff options
context:
space:
mode:
authorLibravatar kim <grufwub@gmail.com>2025-10-17 19:41:06 +0200
committerLibravatar tobi <tobi.smethurst@protonmail.com>2025-11-17 14:11:23 +0100
commit14bf8e62f81d7eac637f2097a88b4c3c32a8a7b5 (patch)
tree56b675dadea6b525336ec9c109d932c224df9df5 /internal/cache
parent[chore] update dependencies (#4507) (diff)
downloadgotosocial-14bf8e62f81d7eac637f2097a88b4c3c32a8a7b5.tar.xz
[performance] reduce account stats database calls (#4496)
Reduces both code complexity and the number of separate database transactions we need to make by moving account statistics operations into the database as side-effects of the operations that effect them. In contrast to currently, where we manually update account statistics at the application layer. Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4496 Co-authored-by: kim <grufwub@gmail.com> Co-committed-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/cache')
-rw-r--r--internal/cache/invalidate.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/internal/cache/invalidate.go b/internal/cache/invalidate.go
index 58c427050..acb602736 100644
--- a/internal/cache/invalidate.go
+++ b/internal/cache/invalidate.go
@@ -138,15 +138,20 @@ func (c *Caches) OnInvalidateFilterStatus(filterStatus *gtsmodel.FilterStatus) {
}
func (c *Caches) OnInvalidateFollow(follow *gtsmodel.Follow) {
+ bothAccountIDs := []string{
+ follow.TargetAccountID,
+ follow.AccountID,
+ }
+
// Invalidate follow request with this same ID.
c.DB.FollowRequest.Invalidate("ID", follow.ID)
+ // Invalidate both follow origin and target account stats.
+ c.DB.AccountStats.InvalidateIDs("AccountID", bothAccountIDs)
+
// Invalidate both follow origin and target as
// possible lookup targets for visibility results.
- c.Visibility.InvalidateIDs("ItemID", []string{
- follow.TargetAccountID,
- follow.AccountID,
- })
+ c.Visibility.InvalidateIDs("ItemID", bothAccountIDs)
// Track which of follow / target are local.
localAccountIDs := make([]string, 0, 2)
@@ -217,6 +222,10 @@ func (c *Caches) OnInvalidateFollowRequest(followReq *gtsmodel.FollowRequest) {
// Invalidate follow with this same ID.
c.DB.Follow.Invalidate("ID", followReq.ID)
+ // Invalidate follow target account stats.
+ c.DB.AccountStats.Invalidate("AccountID",
+ followReq.TargetAccountID)
+
// Invalidate ID slice cache.
c.DB.FollowRequestIDs.Invalidate(