summaryrefslogtreecommitdiff
path: root/internal/processing/workers/fromfediapi.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-04-16 13:10:13 +0200
committerLibravatar GitHub <noreply@github.com>2024-04-16 13:10:13 +0200
commit3cceed11b28b5f42a653d85ed779d652fd8c26ad (patch)
tree0a7f0994e477609ca705a45f382dfb62056b196e /internal/processing/workers/fromfediapi.go
parent[performance] cached oauth database types (#2838) (diff)
downloadgotosocial-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/fromfediapi.go')
-rw-r--r--internal/processing/workers/fromfediapi.go64
1 files changed, 61 insertions, 3 deletions
diff --git a/internal/processing/workers/fromfediapi.go b/internal/processing/workers/fromfediapi.go
index 7b0e72490..0b1106a9e 100644
--- a/internal/processing/workers/fromfediapi.go
+++ b/internal/processing/workers/fromfediapi.go
@@ -122,7 +122,7 @@ func (p *Processor) ProcessFromFediAPI(ctx context.Context, fMsg messages.FromFe
// UPDATE SOMETHING
case ap.ActivityUpdate:
- switch fMsg.APObjectType { //nolint:gocritic
+ switch fMsg.APObjectType {
// UPDATE NOTE/STATUS
case ap.ObjectNote:
@@ -133,6 +133,15 @@ func (p *Processor) ProcessFromFediAPI(ctx context.Context, fMsg messages.FromFe
return p.fediAPI.UpdateAccount(ctx, fMsg)
}
+ // ACCEPT SOMETHING
+ case ap.ActivityAccept:
+ switch fMsg.APObjectType { //nolint:gocritic
+
+ // ACCEPT FOLLOW
+ case ap.ActivityFollow:
+ return p.fediAPI.AcceptFollow(ctx, fMsg)
+ }
+
// DELETE SOMETHING
case ap.ActivityDelete:
switch fMsg.APObjectType {
@@ -220,6 +229,11 @@ func (p *fediAPI) CreateStatus(ctx context.Context, fMsg messages.FromFediAPI) e
return nil
}
+ // Update stats for the remote account.
+ if err := p.utilF.incrementStatusesCount(ctx, fMsg.RequestingAccount, 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. The status dereferencer
@@ -290,14 +304,20 @@ func (p *fediAPI) CreateFollowReq(ctx context.Context, fMsg messages.FromFediAPI
}
if *followRequest.TargetAccount.Locked {
- // Account on our instance is locked: just notify the follow request.
+ // Local account is locked: just notify the follow request.
if err := p.surface.notifyFollowRequest(ctx, followRequest); err != nil {
log.Errorf(ctx, "error notifying follow request: %v", err)
}
+
+ // And update stats for the local account.
+ if err := p.utilF.incrementFollowRequestsCount(ctx, fMsg.ReceivingAccount); err != nil {
+ log.Errorf(ctx, "error updating account stats: %v", err)
+ }
+
return nil
}
- // Account on our instance is not locked:
+ // Local account is not locked:
// Automatically accept the follow request
// and notify about the new follower.
follow, err := p.state.DB.AcceptFollowRequest(
@@ -309,6 +329,16 @@ func (p *fediAPI) CreateFollowReq(ctx context.Context, fMsg messages.FromFediAPI
return gtserror.Newf("error accepting follow request: %w", err)
}
+ // Update stats for the local account.
+ if err := p.utilF.incrementFollowersCount(ctx, fMsg.ReceivingAccount); err != nil {
+ log.Errorf(ctx, "error updating account stats: %v", err)
+ }
+
+ // Update stats for the remote account.
+ if err := p.utilF.incrementFollowingCount(ctx, fMsg.RequestingAccount); 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)
}
@@ -369,6 +399,11 @@ func (p *fediAPI) CreateAnnounce(ctx context.Context, fMsg messages.FromFediAPI)
return gtserror.Newf("error dereferencing announce: %w", err)
}
+ // Update stats for the remote account.
+ if err := p.utilF.incrementStatusesCount(ctx, fMsg.RequestingAccount, 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)
@@ -509,6 +544,24 @@ func (p *fediAPI) UpdateAccount(ctx context.Context, fMsg messages.FromFediAPI)
return nil
}
+func (p *fediAPI) AcceptFollow(ctx context.Context, fMsg messages.FromFediAPI) error {
+ // Update stats for the remote account.
+ if err := p.utilF.decrementFollowRequestsCount(ctx, fMsg.RequestingAccount); err != nil {
+ log.Errorf(ctx, "error updating account stats: %v", err)
+ }
+
+ if err := p.utilF.incrementFollowersCount(ctx, fMsg.RequestingAccount); err != nil {
+ log.Errorf(ctx, "error updating account stats: %v", err)
+ }
+
+ // Update stats for the local account.
+ if err := p.utilF.incrementFollowingCount(ctx, fMsg.ReceivingAccount); err != nil {
+ log.Errorf(ctx, "error updating account stats: %v", err)
+ }
+
+ return nil
+}
+
func (p *fediAPI) UpdateStatus(ctx context.Context, fMsg messages.FromFediAPI) error {
// Cast the existing Status model attached to msg.
existing, ok := fMsg.GTSModel.(*gtsmodel.Status)
@@ -567,6 +620,11 @@ func (p *fediAPI) DeleteStatus(ctx context.Context, fMsg messages.FromFediAPI) e
log.Errorf(ctx, "error wiping status: %v", err)
}
+ // Update stats for the remote account.
+ if err := p.utilF.decrementStatusesCount(ctx, fMsg.RequestingAccount); 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.