mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-07 10:38:06 -06:00
[chore/performance] Avoid unnecessary "uncached" queries (#3265)
* [chore/performance] Avoid unnecessary "uncached" queries * go fmt
This commit is contained in:
parent
f924297af1
commit
25a815a8a4
17 changed files with 149 additions and 21 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue