summaryrefslogtreecommitdiff
path: root/internal/db/bundb/list.go
diff options
context:
space:
mode:
authorLibravatar kim <grufwub@gmail.com>2025-10-15 13:32:02 +0200
committerLibravatar tobi <tobi.smethurst@protonmail.com>2025-10-17 15:33:35 +0200
commit2bdff66f0a12a16684e5d25bcace551446ec1c78 (patch)
tree4a667a71f97d6d2d52d5b3dae1e56d74192219b3 /internal/db/bundb/list.go
parent[chore/performance] Use CTE for list select statuses query (#4501) (diff)
downloadgotosocial-2bdff66f0a12a16684e5d25bcace551446ec1c78.tar.xz
[performance] cache account IDs in home timeline query not in exclusive lists (#4502)
this caches the stage of the home timeline query in which we calculate which account IDs should be shown in a particular user's timeline. Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4502 Co-authored-by: kim <grufwub@gmail.com> Co-committed-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/db/bundb/list.go')
-rw-r--r--internal/db/bundb/list.go19
1 files changed, 16 insertions, 3 deletions
diff --git a/internal/db/bundb/list.go b/internal/db/bundb/list.go
index e1afa64d4..3181dafcc 100644
--- a/internal/db/bundb/list.go
+++ b/internal/db/bundb/list.go
@@ -20,7 +20,6 @@ package bundb
import (
"context"
"errors"
- "fmt"
"slices"
"time"
@@ -358,13 +357,13 @@ func (l *listDB) PopulateListEntry(ctx context.Context, listEntry *gtsmodel.List
var err error
if listEntry.Follow == nil {
- // ListEntry follow is not set, fetch from the database.
+ // ListEntry follow is not set, fetch from database.
listEntry.Follow, err = l.state.DB.GetFollowByID(
gtscontext.SetBarebones(ctx),
listEntry.FollowID,
)
if err != nil {
- return fmt.Errorf("error populating listEntry follow: %w", err)
+ return gtserror.Newf("error populating follow: %w", err)
}
}
@@ -454,6 +453,10 @@ func (l *listDB) DeleteAllListEntriesByFollows(ctx context.Context, followIDs ..
func (l *listDB) invalidateEntryCaches(ctx context.Context, listIDs, followIDs []string) {
var keys []string
+ // Anything requested in this func
+ // will only ever be barbones model.
+ ctx = gtscontext.SetBarebones(ctx)
+
// Generate ListedID keys to invalidate.
keys = slices.Grow(keys[:0], 2*len(listIDs))
for _, listID := range listIDs {
@@ -464,6 +467,16 @@ func (l *listDB) invalidateEntryCaches(ctx context.Context, listIDs, followIDs [
// Invalidate list timeline cache by ID.
l.state.Caches.Timelines.List.Clear(listID)
+
+ // Fetch from DB the list by given ID.
+ list, err := l.GetListByID(ctx, listID)
+ if err != nil {
+ log.Errorf(ctx, "error getting list: %v", err)
+ continue
+ }
+
+ // Invalidate home account IDs slice cache for list owner.
+ l.state.Caches.DB.HomeAccountIDs.Invalidate(list.AccountID)
}
// Invalidate ListedID slice cache entries.