From 83d70f330029de1784b5b66711ebaf093bc2b2d4 Mon Sep 17 00:00:00 2001 From: Namekuji Date: Sat, 15 Apr 2023 02:20:26 -0400 Subject: [PATCH] decrease followersCount if followed by the old account --- packages/backend/src/core/AccountMoveService.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/backend/src/core/AccountMoveService.ts b/packages/backend/src/core/AccountMoveService.ts index 1b89512d01..8056803dfe 100644 --- a/packages/backend/src/core/AccountMoveService.ts +++ b/packages/backend/src/core/AccountMoveService.ts @@ -243,6 +243,12 @@ export class AccountMoveService { // Decrease following counts of local followers by 1. await this.usersRepository.decrement({ id: In(localFollowerIds) }, 'followingCount', 1); + // Decrease follower counts of local followees by 1. + const oldFollowings = await this.followingsRepository.findBy({ followerId: oldAccount.id }); + if (oldFollowings.length > 0) { + await this.usersRepository.decrement({ id: In(oldFollowings.map(following => following.followeeId)) }, 'followersCount', 1); + } + // Update instance stats by decreasing remote followers count by the number of local followers who were following the old account. if (this.userEntityService.isRemoteUser(oldAccount)) { this.federatedInstanceService.fetch(oldAccount.host).then(async i => {