mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-10 00:58:07 -06:00
[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
This commit is contained in:
parent
94e87610c4
commit
0f734a2410
8 changed files with 53 additions and 78 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -743,6 +743,10 @@ func (suite *AccountTestSuite) TestAccountStatsAll() {
|
|||
suite.FailNow(err.Error())
|
||||
}
|
||||
|
||||
// Nil out account stats to allow
|
||||
// db to refetch + regenerate them.
|
||||
account.Stats = nil
|
||||
|
||||
// Get stats for a third time, they
|
||||
// should get regenerated now, but
|
||||
// only for local accounts.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue