From 1cf0df024e58432da39fe2d1b317fb5c9ab8bd2e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 13 Oct 2021 16:18:42 +0200 Subject: Fix actor follow counts calculation --- server/lib/activitypub/process/process-follow.ts | 19 ++++++++++--------- server/lib/actor-follow-health-cache.ts | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'server/lib') diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts index f85238f8e..5562f0798 100644 --- a/server/lib/activitypub/process/process-follow.ts +++ b/server/lib/activitypub/process/process-follow.ts @@ -48,12 +48,14 @@ async function processFollow (byActor: MActorSignature, activityId: string, targ return { actorFollow: undefined as MActorFollowActors } } - const [ actorFollow, created ] = await ActorFollowModel.findOrCreate({ - where: { - actorId: byActor.id, - targetActorId: targetActor.id - }, - defaults: { + // Don't use findOrCreate by sequelize that breaks our actor follow hooks + let created = false + let actorFollow: MActorFollowActors = await ActorFollowModel.loadByActorAndTarget(byActor.id, targetActor.id, t) + + if (!actorFollow) { + created = true + + actorFollow = await ActorFollowModel.create({ actorId: byActor.id, targetActorId: targetActor.id, url: activityId, @@ -61,9 +63,8 @@ async function processFollow (byActor: MActorSignature, activityId: string, targ state: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL ? 'pending' : 'accepted' - }, - transaction: t - }) + }, { transaction: t }) + } // Set the follow as accepted if the remote actor follows a channel or account // Or if the instance automatically accepts followers diff --git a/server/lib/actor-follow-health-cache.ts b/server/lib/actor-follow-health-cache.ts index ab8cc98df..34357a97a 100644 --- a/server/lib/actor-follow-health-cache.ts +++ b/server/lib/actor-follow-health-cache.ts @@ -12,7 +12,7 @@ class ActorFollowHealthCache { private pendingBadServer = new Set() private pendingGoodServer = new Set() - private badInboxes = new Set() + private readonly badInboxes = new Set() private constructor () {} -- cgit v1.2.3