summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-09-02 17:13:54 +0200
committerLibravatar GitHub <noreply@github.com>2024-09-02 17:13:54 +0200
commit0560c5ce891cb3f06f63afae660026b1f16d9e7e (patch)
treed824818f88bf642c354e4ebbb19470e93404420e
parent[chore/performance] Avoid unnecessary "uncached" queries (#3265) (diff)
downloadgotosocial-0560c5ce891cb3f06f63afae660026b1f16d9e7e.tar.xz
[chore] Don't try to select zero uncached filters (#3266)
-rw-r--r--internal/db/bundb/filter.go17
1 files changed, 12 insertions, 5 deletions
diff --git a/internal/db/bundb/filter.go b/internal/db/bundb/filter.go
index 526fa2ba3..b84091cd6 100644
--- a/internal/db/bundb/filter.go
+++ b/internal/db/bundb/filter.go
@@ -82,16 +82,23 @@ func (f *filterDB) GetFiltersForAccountID(ctx context.Context, accountID string)
// Get each filter by ID from the cache or DB.
filters, err := f.state.Caches.DB.Filter.LoadIDs("ID",
filterIDs,
- func(uncachedFilterIDs []string) ([]*gtsmodel.Filter, error) {
- uncachedFilters := make([]*gtsmodel.Filter, 0, len(uncachedFilterIDs))
+ func(uncached []string) ([]*gtsmodel.Filter, error) {
+ // Avoid querying
+ // if none uncached.
+ count := len(uncached)
+ if count == 0 {
+ return nil, nil
+ }
+
+ filters := make([]*gtsmodel.Filter, 0, count)
if err := f.db.
NewSelect().
- Model(&uncachedFilters).
- Where("? IN (?)", bun.Ident("id"), bun.In(uncachedFilterIDs)).
+ Model(&filters).
+ Where("? IN (?)", bun.Ident("id"), bun.In(uncached)).
Scan(ctx); err != nil {
return nil, err
}
- return uncachedFilters, nil
+ return filters, nil
},
)
if err != nil {