summaryrefslogtreecommitdiff
path: root/internal/db/bundb/poll.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-09-02 14:00:17 +0200
committerLibravatar GitHub <noreply@github.com>2024-09-02 14:00:17 +0200
commit25a815a8a438b19a5eafe4243093803129d4c49a (patch)
treed0515324b196927c69ff69c2bb4db66ac0e270ac /internal/db/bundb/poll.go
parent[chore]: Bump github.com/minio/minio-go/v7 from 7.0.75 to 7.0.76 (#3262) (diff)
downloadgotosocial-25a815a8a438b19a5eafe4243093803129d4c49a.tar.xz
[chore/performance] Avoid unnecessary "uncached" queries (#3265)
* [chore/performance] Avoid unnecessary "uncached" queries * go fmt
Diffstat (limited to 'internal/db/bundb/poll.go')
-rw-r--r--internal/db/bundb/poll.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/internal/db/bundb/poll.go b/internal/db/bundb/poll.go
index cd82b1b05..5c1d9c6dd 100644
--- a/internal/db/bundb/poll.go
+++ b/internal/db/bundb/poll.go
@@ -274,8 +274,15 @@ func (p *pollDB) GetPollVotes(ctx context.Context, pollID string) ([]*gtsmodel.P
votes, err := p.state.Caches.DB.PollVote.LoadIDs("ID",
voteIDs,
func(uncached []string) ([]*gtsmodel.PollVote, error) {
+ // Avoid querying
+ // if none uncached.
+ count := len(uncached)
+ if count == 0 {
+ return nil, nil
+ }
+
// Preallocate expected length of uncached votes.
- votes := make([]*gtsmodel.PollVote, 0, len(uncached))
+ votes := make([]*gtsmodel.PollVote, 0, count)
// Perform database query scanning
// the remaining (uncached) IDs.