Skip to content

Commit

Permalink
[chore] Don't try to select zero uncached filters
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmethurst committed Sep 2, 2024
1 parent 4be1f78 commit 82d1c0b
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions internal/db/bundb/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 82d1c0b

Please sign in to comment.