mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[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
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user