aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/actor
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-10-13 16:18:42 +0200
committerChocobozzz <me@florianbigard.com>2021-10-13 16:18:42 +0200
commit1cf0df024e58432da39fe2d1b317fb5c9ab8bd2e (patch)
treea9e3e6e3330552fddda81688dd7ce69e099f0b05 /server/models/actor
parentf87d82b93d474d1290b3c641e63a39197193cb7e (diff)
downloadPeerTube-1cf0df024e58432da39fe2d1b317fb5c9ab8bd2e.tar.gz
PeerTube-1cf0df024e58432da39fe2d1b317fb5c9ab8bd2e.tar.zst
PeerTube-1cf0df024e58432da39fe2d1b317fb5c9ab8bd2e.zip
Fix actor follow counts calculation
Diffstat (limited to 'server/models/actor')
-rw-r--r--server/models/actor/actor-follow.ts23
1 files changed, 13 insertions, 10 deletions
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 {
19 UpdatedAt 19 UpdatedAt
20} from 'sequelize-typescript' 20} from 'sequelize-typescript'
21import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc' 21import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc'
22import { afterCommitIfTransaction } from '@server/helpers/database-utils'
22import { getServerActor } from '@server/models/application/application' 23import { getServerActor } from '@server/models/application/application'
23import { 24import {
24 MActorFollowActorsDefault, 25 MActorFollowActorsDefault,
@@ -118,20 +119,22 @@ export class ActorFollowModel extends Model<Partial<AttributesOnly<ActorFollowMo
118 @AfterCreate 119 @AfterCreate
119 @AfterUpdate 120 @AfterUpdate
120 static incrementFollowerAndFollowingCount (instance: ActorFollowModel, options: any) { 121 static incrementFollowerAndFollowingCount (instance: ActorFollowModel, options: any) {
121 if (instance.state !== 'accepted') return undefined 122 return afterCommitIfTransaction(options.transaction, () => {
122 123 return Promise.all([
123 return Promise.all([ 124 ActorModel.rebuildFollowsCount(instance.actorId, 'following'),
124 ActorModel.rebuildFollowsCount(instance.actorId, 'following', options.transaction), 125 ActorModel.rebuildFollowsCount(instance.targetActorId, 'followers')
125 ActorModel.rebuildFollowsCount(instance.targetActorId, 'followers', options.transaction) 126 ])
126 ]) 127 })
127 } 128 }
128 129
129 @AfterDestroy 130 @AfterDestroy
130 static decrementFollowerAndFollowingCount (instance: ActorFollowModel, options: any) { 131 static decrementFollowerAndFollowingCount (instance: ActorFollowModel, options: any) {
131 return Promise.all([ 132 return afterCommitIfTransaction(options.transaction, () => {
132 ActorModel.rebuildFollowsCount(instance.actorId, 'following', options.transaction), 133 return Promise.all([
133 ActorModel.rebuildFollowsCount(instance.targetActorId, 'followers', options.transaction) 134 ActorModel.rebuildFollowsCount(instance.actorId, 'following'),
134 ]) 135 ActorModel.rebuildFollowsCount(instance.targetActorId, 'followers')
136 ])
137 })
135 } 138 }
136 139
137 static removeFollowsOf (actorId: number, t?: Transaction) { 140 static removeFollowsOf (actorId: number, t?: Transaction) {