[chore/performance] Avoid unnecessary "uncached" queries (#3265)

* [chore/performance] Avoid unnecessary "uncached" queries

* go fmt
This commit is contained in:
tobi 2024-09-02 14:00:17 +02:00 committed by GitHub
commit 25a815a8a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 149 additions and 21 deletions

View file

@ -87,8 +87,15 @@ func (r *relationshipDB) getMutesByIDs(ctx context.Context, ids []string) ([]*gt
mutes, err := r.state.Caches.DB.UserMute.LoadIDs("ID",
ids,
func(uncached []string) ([]*gtsmodel.UserMute, error) {
// Avoid querying
// if none uncached.
count := len(uncached)
if count == 0 {
return nil, nil
}
// Preallocate expected length of uncached mutes.
mutes := make([]*gtsmodel.UserMute, 0, len(uncached))
mutes := make([]*gtsmodel.UserMute, 0, count)
// Perform database query scanning
// the remaining (uncached) IDs.