diff options
author | 2024-04-16 13:10:13 +0200 | |
---|---|---|
committer | 2024-04-16 13:10:13 +0200 | |
commit | 3cceed11b28b5f42a653d85ed779d652fd8c26ad (patch) | |
tree | 0a7f0994e477609ca705a45f382dfb62056b196e /internal/processing/workers/fromclientapi.go | |
parent | [performance] cached oauth database types (#2838) (diff) | |
download | gotosocial-3cceed11b28b5f42a653d85ed779d652fd8c26ad.tar.xz |
[feature/performance] Store account stats in separate table (#2831)
* [feature/performance] Store account stats in separate table, get stats from remote
* test account stats
* add some missing increment / decrement calls
* change stats function signatures
* rejig logging a bit
* use lock when updating stats
Diffstat (limited to 'internal/processing/workers/fromclientapi.go')
-rw-r--r-- | internal/processing/workers/fromclientapi.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/internal/processing/workers/fromclientapi.go b/internal/processing/workers/fromclientapi.go index 37c330cf0..1412ea003 100644 --- a/internal/processing/workers/fromclientapi.go +++ b/internal/processing/workers/fromclientapi.go @@ -247,6 +247,11 @@ func (p *clientAPI) CreateStatus(ctx context.Context, cMsg messages.FromClientAP return gtserror.Newf("%T not parseable as *gtsmodel.Status", cMsg.GTSModel) } + // Update stats for the actor account. + if err := p.utilF.incrementStatusesCount(ctx, cMsg.OriginAccount, 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) } @@ -311,6 +316,11 @@ func (p *clientAPI) CreateFollowReq(ctx context.Context, cMsg messages.FromClien return gtserror.Newf("%T not parseable as *gtsmodel.FollowRequest", cMsg.GTSModel) } + // Update stats for the target account. + if err := p.utilF.incrementFollowRequestsCount(ctx, cMsg.TargetAccount); err != nil { + log.Errorf(ctx, "error updating account stats: %v", err) + } + if err := p.surface.notifyFollowRequest(ctx, followRequest); err != nil { log.Errorf(ctx, "error notifying follow request: %v", err) } @@ -360,6 +370,11 @@ func (p *clientAPI) CreateAnnounce(ctx context.Context, cMsg messages.FromClient return gtserror.Newf("%T not parseable as *gtsmodel.Status", cMsg.GTSModel) } + // Update stats for the actor account. + if err := p.utilF.incrementStatusesCount(ctx, cMsg.OriginAccount, 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) @@ -485,6 +500,20 @@ func (p *clientAPI) AcceptFollow(ctx context.Context, cMsg messages.FromClientAP return gtserror.Newf("%T not parseable as *gtsmodel.Follow", cMsg.GTSModel) } + // Update stats for the target account. + if err := p.utilF.decrementFollowRequestsCount(ctx, cMsg.TargetAccount); err != nil { + log.Errorf(ctx, "error updating account stats: %v", err) + } + + if err := p.utilF.incrementFollowersCount(ctx, cMsg.TargetAccount); err != nil { + log.Errorf(ctx, "error updating account stats: %v", err) + } + + // Update stats for the origin account. + if err := p.utilF.incrementFollowingCount(ctx, cMsg.OriginAccount); err != nil { + log.Errorf(ctx, "error updating account stats: %v", err) + } + if err := p.surface.notifyFollow(ctx, follow); err != nil { log.Errorf(ctx, "error notifying follow: %v", err) } @@ -502,6 +531,11 @@ func (p *clientAPI) RejectFollowRequest(ctx context.Context, cMsg messages.FromC return gtserror.Newf("%T not parseable as *gtsmodel.FollowRequest", cMsg.GTSModel) } + // Update stats for the target account. + if err := p.utilF.decrementFollowRequestsCount(ctx, cMsg.TargetAccount); err != nil { + log.Errorf(ctx, "error updating account stats: %v", err) + } + if err := p.federate.RejectFollow( ctx, p.converter.FollowRequestToFollow(ctx, followReq), @@ -518,6 +552,16 @@ func (p *clientAPI) UndoFollow(ctx context.Context, cMsg messages.FromClientAPI) return gtserror.Newf("%T not parseable as *gtsmodel.Follow", cMsg.GTSModel) } + // Update stats for the origin account. + if err := p.utilF.decrementFollowingCount(ctx, cMsg.OriginAccount); err != nil { + log.Errorf(ctx, "error updating account stats: %v", err) + } + + // Update stats for the target account. + if err := p.utilF.decrementFollowersCount(ctx, cMsg.TargetAccount); err != nil { + log.Errorf(ctx, "error updating account stats: %v", err) + } + if err := p.federate.UndoFollow(ctx, follow); err != nil { log.Errorf(ctx, "error federating follow undo: %v", err) } @@ -565,6 +609,11 @@ func (p *clientAPI) UndoAnnounce(ctx context.Context, cMsg messages.FromClientAP return gtserror.Newf("db error deleting status: %w", err) } + // Update stats for the origin account. + if err := p.utilF.decrementStatusesCount(ctx, cMsg.OriginAccount); err != nil { + log.Errorf(ctx, "error updating account stats: %v", err) + } + if err := p.surface.deleteStatusFromTimelines(ctx, status.ID); err != nil { log.Errorf(ctx, "error removing timelined status: %v", err) } @@ -603,6 +652,11 @@ func (p *clientAPI) DeleteStatus(ctx context.Context, cMsg messages.FromClientAP log.Errorf(ctx, "error wiping status: %v", err) } + // Update stats for the origin account. + if err := p.utilF.decrementStatusesCount(ctx, cMsg.OriginAccount); 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. |