From 0560c5ce891cb3f06f63afae660026b1f16d9e7e Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Mon, 2 Sep 2024 17:13:54 +0200 Subject: [PATCH] [chore] Don't try to select zero uncached filters (#3266) --- internal/db/bundb/filter.go | 17 ++++++++++++----- 1 file 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 {