diff options
author | 2024-08-11 09:23:36 +0000 | |
---|---|---|
committer | 2024-08-11 11:23:36 +0200 | |
commit | 865b3aeaac8f165462796a7a5f8cf04ae7724d0f (patch) | |
tree | e17d58bf351e99fb512900ed5c3b6a60fe7c6196 /internal/processing/workers/util.go | |
parent | [bugfix] ensure testrig package only compiled-in when debug enabled (#3185) (diff) | |
download | gotosocial-865b3aeaac8f165462796a7a5f8cf04ae7724d0f.tar.xz |
[bugfix] updated pinned counts on status delete (#3188)
* include pinned status when incrementing / decrementing status counts
* remove the pinned increment on status creation
* code comments
* microoptimize decr
Diffstat (limited to 'internal/processing/workers/util.go')
-rw-r--r-- | internal/processing/workers/util.go | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/internal/processing/workers/util.go b/internal/processing/workers/util.go index 7f6c259de..49c6183a4 100644 --- a/internal/processing/workers/util.go +++ b/internal/processing/workers/util.go @@ -256,17 +256,17 @@ func (u *utils) incrementStatusesCount( unlock := u.state.ProcessingLocks.Lock(account.URI) defer unlock() - // Populate stats. + // Ensure account stats are populated. if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { return gtserror.Newf("db error getting account stats: %w", err) } - // Update stats by incrementing status - // count by one and setting last posted. + // Update status meta for account. *account.Stats.StatusesCount++ account.Stats.LastStatusAt = status.CreatedAt - if err := u.state.DB.UpdateAccountStats( - ctx, + + // Update details in the database for stats. + if err := u.state.DB.UpdateAccountStats(ctx, account.Stats, "statuses_count", "last_status_at", @@ -280,28 +280,30 @@ func (u *utils) incrementStatusesCount( func (u *utils) decrementStatusesCount( ctx context.Context, account *gtsmodel.Account, + status *gtsmodel.Status, ) error { // Lock on this account since we're changing stats. unlock := u.state.ProcessingLocks.Lock(account.URI) defer unlock() - // Populate stats. + // Ensure account stats are populated. if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { return gtserror.Newf("db error getting account stats: %w", err) } - // Update stats by decrementing - // status count by one. - // - // Clamp to 0 to avoid funny business. - *account.Stats.StatusesCount-- - if *account.Stats.StatusesCount < 0 { - *account.Stats.StatusesCount = 0 + // Update status meta for account (safely checking for zero value). + *account.Stats.StatusesCount = util.Decr(*account.Stats.StatusesCount) + + if !status.PinnedAt.IsZero() { + // Update status pinned count for account (safely checking for zero value). + *account.Stats.StatusesPinnedCount = util.Decr(*account.Stats.StatusesPinnedCount) } - if err := u.state.DB.UpdateAccountStats( - ctx, + + // Update details in the database for stats. + if err := u.state.DB.UpdateAccountStats(ctx, account.Stats, "statuses_count", + "statuses_pinned_count", ); err != nil { return gtserror.Newf("db error updating account stats: %w", err) } @@ -317,7 +319,7 @@ func (u *utils) incrementFollowersCount( unlock := u.state.ProcessingLocks.Lock(account.URI) defer unlock() - // Populate stats. + // Ensure account stats are populated. if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { return gtserror.Newf("db error getting account stats: %w", err) } @@ -344,7 +346,7 @@ func (u *utils) decrementFollowersCount( unlock := u.state.ProcessingLocks.Lock(account.URI) defer unlock() - // Populate stats. + // Ensure account stats are populated. if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { return gtserror.Newf("db error getting account stats: %w", err) } @@ -376,7 +378,7 @@ func (u *utils) incrementFollowingCount( unlock := u.state.ProcessingLocks.Lock(account.URI) defer unlock() - // Populate stats. + // Ensure account stats are populated. if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { return gtserror.Newf("db error getting account stats: %w", err) } @@ -403,7 +405,7 @@ func (u *utils) decrementFollowingCount( unlock := u.state.ProcessingLocks.Lock(account.URI) defer unlock() - // Populate stats. + // Ensure account stats are populated. if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { return gtserror.Newf("db error getting account stats: %w", err) } @@ -435,7 +437,7 @@ func (u *utils) incrementFollowRequestsCount( unlock := u.state.ProcessingLocks.Lock(account.URI) defer unlock() - // Populate stats. + // Ensure account stats are populated. if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { return gtserror.Newf("db error getting account stats: %w", err) } @@ -462,7 +464,7 @@ func (u *utils) decrementFollowRequestsCount( unlock := u.state.ProcessingLocks.Lock(account.URI) defer unlock() - // Populate stats. + // Ensure account stats are populated. if err := u.state.DB.PopulateAccountStats(ctx, account); err != nil { return gtserror.Newf("db error getting account stats: %w", err) } |