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/models/actor/actor-follow.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'server/models/actor') diff --git a/server/models/actor/actor-follow.ts b/server/models/actor/actor-follow.ts index 283856d3f..95bb2df56 100644 --- a/server/models/actor/actor-follow.ts +++ b/server/models/actor/actor-follow.ts @@ -19,6 +19,7 @@ import { UpdatedAt } from 'sequelize-typescript' import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc' +import { afterCommitIfTransaction } from '@server/helpers/database-utils' import { getServerActor } from '@server/models/application/application' import { MActorFollowActorsDefault, @@ -118,20 +119,22 @@ export class ActorFollowModel extends Model { + return Promise.all([ + ActorModel.rebuildFollowsCount(instance.actorId, 'following'), + ActorModel.rebuildFollowsCount(instance.targetActorId, 'followers') + ]) + }) } @AfterDestroy static decrementFollowerAndFollowingCount (instance: ActorFollowModel, options: any) { - return Promise.all([ - ActorModel.rebuildFollowsCount(instance.actorId, 'following', options.transaction), - ActorModel.rebuildFollowsCount(instance.targetActorId, 'followers', options.transaction) - ]) + return afterCommitIfTransaction(options.transaction, () => { + return Promise.all([ + ActorModel.rebuildFollowsCount(instance.actorId, 'following'), + ActorModel.rebuildFollowsCount(instance.targetActorId, 'followers') + ]) + }) } static removeFollowsOf (actorId: number, t?: Transaction) { -- cgit v1.2.3