mirror of
1
Fork 0

[chore] Don't try to select zero uncached filters (#3266)

This commit is contained in:
tobi 2024-09-02 17:13:54 +02:00 committed by GitHub
parent 25a815a8a4
commit 0560c5ce89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 5 deletions

View File

@ -82,16 +82,23 @@ func (f *filterDB) GetFiltersForAccountID(ctx context.Context, accountID string)
// Get each filter by ID from the cache or DB. // Get each filter by ID from the cache or DB.
filters, err := f.state.Caches.DB.Filter.LoadIDs("ID", filters, err := f.state.Caches.DB.Filter.LoadIDs("ID",
filterIDs, filterIDs,
func(uncachedFilterIDs []string) ([]*gtsmodel.Filter, error) { func(uncached []string) ([]*gtsmodel.Filter, error) {
uncachedFilters := make([]*gtsmodel.Filter, 0, len(uncachedFilterIDs)) // Avoid querying
// if none uncached.
count := len(uncached)
if count == 0 {
return nil, nil
}
filters := make([]*gtsmodel.Filter, 0, count)
if err := f.db. if err := f.db.
NewSelect(). NewSelect().
Model(&uncachedFilters). Model(&filters).
Where("? IN (?)", bun.Ident("id"), bun.In(uncachedFilterIDs)). Where("? IN (?)", bun.Ident("id"), bun.In(uncached)).
Scan(ctx); err != nil { Scan(ctx); err != nil {
return nil, err return nil, err
} }
return uncachedFilters, nil return filters, nil
}, },
) )
if err != nil { if err != nil {