diff options
| author | 2025-10-17 19:41:06 +0200 | |
|---|---|---|
| committer | 2025-11-17 14:11:23 +0100 | |
| commit | 14bf8e62f81d7eac637f2097a88b4c3c32a8a7b5 (patch) | |
| tree | 56b675dadea6b525336ec9c109d932c224df9df5 /internal/processing/workers/fromfediapi.go | |
| parent | [chore] update dependencies (#4507) (diff) | |
| download | gotosocial-14bf8e62f81d7eac637f2097a88b4c3c32a8a7b5.tar.xz | |
[performance] reduce account stats database calls (#4496)
Reduces both code complexity and the number of separate database transactions we need to make by moving account statistics operations into the database as side-effects of the operations that effect them. In contrast to currently, where we manually update account statistics at the application layer.
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4496
Co-authored-by: kim <grufwub@gmail.com>
Co-committed-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/processing/workers/fromfediapi.go')
| -rw-r--r-- | internal/processing/workers/fromfediapi.go | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/internal/processing/workers/fromfediapi.go b/internal/processing/workers/fromfediapi.go index 797a2d9c6..b64b8bbec 100644 --- a/internal/processing/workers/fromfediapi.go +++ b/internal/processing/workers/fromfediapi.go @@ -369,11 +369,6 @@ func (p *fediAPI) CreateStatus(ctx context.Context, fMsg *messages.FromFediAPI) // Don't return, just continue as normal. } - // Update stats for the remote account. - if err := p.utils.incrementStatusesCount(ctx, fMsg.Requesting, status); err != nil { - log.Errorf(ctx, "error updating account stats: %v", err) - } - if err := p.surface.timelineAndNotifyStatus(ctx, status); err != nil { log.Errorf(ctx, "error timelining and notifying status: %v", err) } @@ -483,11 +478,6 @@ func (p *fediAPI) CreateReplyRequest(ctx context.Context, fMsg *messages.FromFed log.Errorf(ctx, "error federating accept: %v", err) } - // Update stats for the replying account. - if err := p.utils.incrementStatusesCount(ctx, fMsg.Requesting, reply); err != nil { - log.Errorf(ctx, "error updating account stats: %v", err) - } - // Timeline the reply + notify recipient(s). if err := p.surface.timelineAndNotifyStatus(ctx, reply); err != nil { log.Errorf(ctx, "error timelining and notifying status: %v", err) @@ -597,11 +587,6 @@ func (p *fediAPI) CreateFollowReq(ctx context.Context, fMsg *messages.FromFediAP log.Errorf(ctx, "error notifying follow request: %v", err) } - // And update stats for the local account. - if err := p.utils.incrementFollowRequestsCount(ctx, fMsg.Receiving); err != nil { - log.Errorf(ctx, "error updating account stats: %v", err) - } - return nil } @@ -617,16 +602,6 @@ func (p *fediAPI) CreateFollowReq(ctx context.Context, fMsg *messages.FromFediAP return gtserror.Newf("error accepting follow request: %w", err) } - // Update stats for the local account. - if err := p.utils.incrementFollowersCount(ctx, fMsg.Receiving); err != nil { - log.Errorf(ctx, "error updating account stats: %v", err) - } - - // Update stats for the remote account. - if err := p.utils.incrementFollowingCount(ctx, fMsg.Requesting); err != nil { - log.Errorf(ctx, "error updating account stats: %v", err) - } - if err := p.federate.AcceptFollow(ctx, follow); err != nil { log.Errorf(ctx, "error federating follow request accept: %v", err) } @@ -913,11 +888,6 @@ func (p *fediAPI) CreateAnnounce(ctx context.Context, fMsg *messages.FromFediAPI // Don't return, just continue as normal. } - // Update stats for the remote account. - if err := p.utils.incrementStatusesCount(ctx, fMsg.Requesting, boost); err != nil { - log.Errorf(ctx, "error updating account stats: %v", err) - } - // Timeline and notify the announce. if err := p.surface.timelineAndNotifyStatus(ctx, boost); err != nil { log.Errorf(ctx, "error timelining and notifying status: %v", err) @@ -1014,11 +984,6 @@ func (p *fediAPI) CreateAnnounceRequest(ctx context.Context, fMsg *messages.From log.Errorf(ctx, "error federating accept: %v", err) } - // Update stats for the boosting account. - if err := p.utils.incrementStatusesCount(ctx, fMsg.Requesting, boost); err != nil { - log.Errorf(ctx, "error updating account stats: %v", err) - } - // Timeline the boost + notify recipient(s). if err := p.surface.timelineAndNotifyStatus(ctx, boost); err != nil { log.Errorf(ctx, "error timelining and notifying status: %v", err) @@ -1141,20 +1106,6 @@ func (p *fediAPI) UpdateAccount(ctx context.Context, fMsg *messages.FromFediAPI) } func (p *fediAPI) AcceptFollow(ctx context.Context, fMsg *messages.FromFediAPI) error { - // Update stats for the remote account. - if err := p.utils.decrementFollowRequestsCount(ctx, fMsg.Requesting); err != nil { - log.Errorf(ctx, "error updating account stats: %v", err) - } - - if err := p.utils.incrementFollowersCount(ctx, fMsg.Requesting); err != nil { - log.Errorf(ctx, "error updating account stats: %v", err) - } - - // Update stats for the local account. - if err := p.utils.incrementFollowingCount(ctx, fMsg.Receiving); err != nil { - log.Errorf(ctx, "error updating account stats: %v", err) - } - return nil } @@ -1170,11 +1121,6 @@ func (p *fediAPI) AcceptReply(ctx context.Context, fMsg *messages.FromFediAPI) e return gtserror.Newf("%T not parseable as *gtsmodel.Status", fMsg.GTSModel) } - // Update stats for the actor account. - if err := p.utils.incrementStatusesCount(ctx, reply.Account, reply); err != nil { - log.Errorf(ctx, "error updating account stats: %v", err) - } - // Timeline and notify the status. if err := p.surface.timelineAndNotifyStatus(ctx, reply); err != nil { log.Errorf(ctx, "error timelining and notifying status: %v", err) @@ -1274,11 +1220,6 @@ func (p *fediAPI) AcceptPoliteReplyRequest(ctx context.Context, fMsg *messages.F return gtserror.Newf("error populating status: %w", err) } - // Update stats for the actor account. - if err := p.utils.incrementStatusesCount(ctx, reply.Account, reply); err != nil { - log.Errorf(ctx, "error updating account stats: %v", err) - } - // Timeline and notify the status. if err := p.surface.timelineAndNotifyStatus(ctx, reply); err != nil { log.Errorf(ctx, "error timelining and notifying status: %v", err) @@ -1302,11 +1243,6 @@ func (p *fediAPI) AcceptAnnounce(ctx context.Context, fMsg *messages.FromFediAPI return gtserror.Newf("%T not parseable as *gtsmodel.Status", fMsg.GTSModel) } - // Update stats for the actor account. - if err := p.utils.incrementStatusesCount(ctx, boost.Account, boost); err != nil { - log.Errorf(ctx, "error updating account stats: %v", err) - } - // Timeline and notify the boost wrapper status. if err := p.surface.timelineAndNotifyStatus(ctx, boost); err != nil { log.Errorf(ctx, "error timelining and notifying status: %v", err) @@ -1455,11 +1391,6 @@ func (p *fediAPI) DeleteStatus(ctx context.Context, fMsg *messages.FromFediAPI) log.Errorf(ctx, "error wiping status: %v", err) } - // Update stats for the remote account. - if err := p.utils.decrementStatusesCount(ctx, fMsg.Requesting, status); err != nil { - log.Errorf(ctx, "error updating account stats: %v", err) - } - if status.InReplyToID != "" { // Interaction counts changed on the replied status; // uncache the prepared version from all timelines. @@ -1661,11 +1592,6 @@ func (p *fediAPI) UndoAnnounce( return gtserror.Newf("db error deleting boost: %w", err) } - // Update statuses count for the requesting account. - if err := p.utils.decrementStatusesCount(ctx, fMsg.Requesting, boost); err != nil { - log.Errorf(ctx, "error updating account stats: %v", err) - } - // Remove the boost wrapper from all timelines. p.surface.deleteStatusFromTimelines(ctx, boost.ID) |
