diff options
Diffstat (limited to 'server/models/actor/actor-follow.ts')
-rw-r--r-- | server/models/actor/actor-follow.ts | 23 |
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' |
21 | import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc' | 21 | import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc' |
22 | import { afterCommitIfTransaction } from '@server/helpers/database-utils' | ||
22 | import { getServerActor } from '@server/models/application/application' | 23 | import { getServerActor } from '@server/models/application/application' |
23 | import { | 24 | import { |
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) { |