aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/activitypub/actor.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-01-08 15:11:38 +0100
committerChocobozzz <me@florianbigard.com>2020-01-08 15:44:41 +0100
commite612209767ebe1deb0af7688c96b7f979bb52b44 (patch)
treec5be9241e41a098f5452fe3cd187e2305d8047e3 /server/models/activitypub/actor.ts
parent440d39c52d4efb878b6a2e21584d6b8f52072f27 (diff)
downloadPeerTube-e612209767ebe1deb0af7688c96b7f979bb52b44.tar.gz
PeerTube-e612209767ebe1deb0af7688c96b7f979bb52b44.tar.zst
PeerTube-e612209767ebe1deb0af7688c96b7f979bb52b44.zip
Try to fix subscriptions inconsistencies
Diffstat (limited to 'server/models/activitypub/actor.ts')
-rw-r--r--server/models/activitypub/actor.ts27
1 files changed, 19 insertions, 8 deletions
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts
index 58b52ffb1..007647ced 100644
--- a/server/models/activitypub/actor.ts
+++ b/server/models/activitypub/actor.ts
@@ -47,7 +47,7 @@ import {
47 MActorWithInboxes 47 MActorWithInboxes
48} from '../../typings/models' 48} from '../../typings/models'
49import * as Bluebird from 'bluebird' 49import * as Bluebird from 'bluebird'
50import { Op, Transaction } from 'sequelize' 50import { Op, Transaction, literal } from 'sequelize'
51 51
52enum ScopeNames { 52enum ScopeNames {
53 FULL = 'FULL' 53 FULL = 'FULL'
@@ -421,13 +421,24 @@ export class ActorModel extends Model<ActorModel> {
421 return ActorModel.scope(ScopeNames.FULL).findOne(query) 421 return ActorModel.scope(ScopeNames.FULL).findOne(query)
422 } 422 }
423 423
424 static incrementFollows (id: number, column: 'followersCount' | 'followingCount', by: number) { 424 static rebuildFollowsCount (ofId: number, type: 'followers' | 'following', transaction?: Transaction) {
425 return ActorModel.increment(column, { 425 const sanitizedOfId = parseInt(ofId + '', 10)
426 by, 426 const where = { id: sanitizedOfId }
427 where: { 427
428 id 428 let columnToUpdate: string
429 } 429 let columnOfCount: string
430 }) 430
431 if (type === 'followers') {
432 columnToUpdate = 'followersCount'
433 columnOfCount = 'targetActorId'
434 } else {
435 columnToUpdate = 'followingCount'
436 columnOfCount = 'actorId'
437 }
438
439 return ActorModel.update({
440 [columnToUpdate]: literal(`(SELECT COUNT(*) FROM "actorFollow" WHERE "${columnOfCount}" = ${sanitizedOfId})`)
441 }, { where, transaction })
431 } 442 }
432 443
433 getSharedInbox (this: MActorWithInboxes) { 444 getSharedInbox (this: MActorWithInboxes) {