diff options
author | 2024-08-02 12:15:11 +0000 | |
---|---|---|
committer | 2024-08-02 13:15:11 +0100 | |
commit | 0f734a24100383171a866fccc194dea578141d74 (patch) | |
tree | a2cfdebeb1098ef39a8b2907a0933ac7f18a3ca3 /internal/db/bundb/account.go | |
parent | [chore] add back exif-terminator and use only for jpeg,png,webp (#3161) (diff) | |
download | gotosocial-0f734a24100383171a866fccc194dea578141d74.tar.xz |
[chore] move PopulateAccountStats() nil check often performed into function itself (#3158)
* move PopulateAccountStats() nil check often performed into function itself
* fix test to take in mind we don't repopulate account stats if not-nil
Diffstat (limited to 'internal/db/bundb/account.go')
-rw-r--r-- | internal/db/bundb/account.go | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/internal/db/bundb/account.go b/internal/db/bundb/account.go index 90bf3eb65..94fd054bf 100644 --- a/internal/db/bundb/account.go +++ b/internal/db/bundb/account.go @@ -712,11 +712,9 @@ func (a *accountDB) PopulateAccount(ctx context.Context, account *gtsmodel.Accou } } - if account.Stats == nil { - // Get / Create stats for this account. - if err := a.state.DB.PopulateAccountStats(ctx, account); err != nil { - errs.Appendf("error populating account stats: %w", err) - } + // Get / Create stats for this account (handles case of already set). + if err := a.state.DB.PopulateAccountStats(ctx, account); err != nil { + errs.Appendf("error populating account stats: %w", err) } return errs.Combine() @@ -1160,6 +1158,11 @@ func (a *accountDB) UpdateAccountSettings( } func (a *accountDB) PopulateAccountStats(ctx context.Context, account *gtsmodel.Account) error { + if account.Stats != nil { + // Already populated! + return nil + } + // Fetch stats from db cache with loader callback. stats, err := a.state.Caches.DB.AccountStats.LoadOne( "AccountID", |