diff options
| author | 2024-09-02 14:00:17 +0200 | |
|---|---|---|
| committer | 2024-09-02 14:00:17 +0200 | |
| commit | 25a815a8a438b19a5eafe4243093803129d4c49a (patch) | |
| tree | d0515324b196927c69ff69c2bb4db66ac0e270ac /internal/db/bundb/application.go | |
| parent | [chore]: Bump github.com/minio/minio-go/v7 from 7.0.75 to 7.0.76 (#3262) (diff) | |
| download | gotosocial-25a815a8a438b19a5eafe4243093803129d4c49a.tar.xz | |
[chore/performance] Avoid unnecessary "uncached" queries (#3265)
* [chore/performance] Avoid unnecessary "uncached" queries
* go fmt
Diffstat (limited to 'internal/db/bundb/application.go')
| -rw-r--r-- | internal/db/bundb/application.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/internal/db/bundb/application.go b/internal/db/bundb/application.go index fda0ba602..72c4ec206 100644 --- a/internal/db/bundb/application.go +++ b/internal/db/bundb/application.go @@ -147,8 +147,15 @@ func (a *applicationDB) GetAllTokens(ctx context.Context) ([]*gtsmodel.Token, er tokens, err := a.state.Caches.DB.Token.LoadIDs("ID", tokenIDs, func(uncached []string) ([]*gtsmodel.Token, error) { + // Avoid querying + // if none uncached. + count := len(uncached) + if count == 0 { + return nil, nil + } + // Preallocate expected length of uncached tokens. - tokens := make([]*gtsmodel.Token, 0, len(uncached)) + tokens := make([]*gtsmodel.Token, 0, count) // Perform database query scanning // the remaining (uncached) token IDs. |
