diff options
Diffstat (limited to 'server/models/activitypub')
-rw-r--r-- | server/models/activitypub/actor-follow.ts | 50 |
1 files changed, 16 insertions, 34 deletions
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts index 0a6935083..994f791de 100644 --- a/server/models/activitypub/actor-follow.ts +++ b/server/models/activitypub/actor-follow.ts | |||
@@ -127,22 +127,6 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
127 | if (numberOfActorFollowsRemoved) logger.info('Removed bad %d actor follows.', numberOfActorFollowsRemoved) | 127 | if (numberOfActorFollowsRemoved) logger.info('Removed bad %d actor follows.', numberOfActorFollowsRemoved) |
128 | } | 128 | } |
129 | 129 | ||
130 | static updateActorFollowsScore (goodInboxes: string[], badInboxes: string[], t: Sequelize.Transaction | undefined) { | ||
131 | if (goodInboxes.length === 0 && badInboxes.length === 0) return | ||
132 | |||
133 | logger.info('Updating %d good actor follows and %d bad actor follows scores.', goodInboxes.length, badInboxes.length) | ||
134 | |||
135 | if (goodInboxes.length !== 0) { | ||
136 | ActorFollowModel.incrementScores(goodInboxes, ACTOR_FOLLOW_SCORE.BONUS, t) | ||
137 | .catch(err => logger.error('Cannot increment scores of good actor follows.', { err })) | ||
138 | } | ||
139 | |||
140 | if (badInboxes.length !== 0) { | ||
141 | ActorFollowModel.incrementScores(badInboxes, ACTOR_FOLLOW_SCORE.PENALTY, t) | ||
142 | .catch(err => logger.error('Cannot decrement scores of bad actor follows.', { err })) | ||
143 | } | ||
144 | } | ||
145 | |||
146 | static loadByActorAndTarget (actorId: number, targetActorId: number, t?: Sequelize.Transaction) { | 130 | static loadByActorAndTarget (actorId: number, targetActorId: number, t?: Sequelize.Transaction) { |
147 | const query = { | 131 | const query = { |
148 | where: { | 132 | where: { |
@@ -464,6 +448,22 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
464 | } | 448 | } |
465 | } | 449 | } |
466 | 450 | ||
451 | static updateFollowScore (inboxUrl: string, value: number, t?: Sequelize.Transaction) { | ||
452 | const query = `UPDATE "actorFollow" SET "score" = LEAST("score" + ${value}, ${ACTOR_FOLLOW_SCORE.MAX}) ` + | ||
453 | 'WHERE id IN (' + | ||
454 | 'SELECT "actorFollow"."id" FROM "actorFollow" ' + | ||
455 | 'INNER JOIN "actor" ON "actor"."id" = "actorFollow"."actorId" ' + | ||
456 | `WHERE "actor"."inboxUrl" = '${inboxUrl}' OR "actor"."sharedInboxUrl" = '${inboxUrl}'` + | ||
457 | ')' | ||
458 | |||
459 | const options = { | ||
460 | type: Sequelize.QueryTypes.BULKUPDATE, | ||
461 | transaction: t | ||
462 | } | ||
463 | |||
464 | return ActorFollowModel.sequelize.query(query, options) | ||
465 | } | ||
466 | |||
467 | private static async createListAcceptedFollowForApiQuery ( | 467 | private static async createListAcceptedFollowForApiQuery ( |
468 | type: 'followers' | 'following', | 468 | type: 'followers' | 'following', |
469 | actorIds: number[], | 469 | actorIds: number[], |
@@ -518,24 +518,6 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
518 | } | 518 | } |
519 | } | 519 | } |
520 | 520 | ||
521 | private static incrementScores (inboxUrls: string[], value: number, t: Sequelize.Transaction | undefined) { | ||
522 | const inboxUrlsString = inboxUrls.map(url => `'${url}'`).join(',') | ||
523 | |||
524 | const query = `UPDATE "actorFollow" SET "score" = LEAST("score" + ${value}, ${ACTOR_FOLLOW_SCORE.MAX}) ` + | ||
525 | 'WHERE id IN (' + | ||
526 | 'SELECT "actorFollow"."id" FROM "actorFollow" ' + | ||
527 | 'INNER JOIN "actor" ON "actor"."id" = "actorFollow"."actorId" ' + | ||
528 | 'WHERE "actor"."inboxUrl" IN (' + inboxUrlsString + ') OR "actor"."sharedInboxUrl" IN (' + inboxUrlsString + ')' + | ||
529 | ')' | ||
530 | |||
531 | const options = t ? { | ||
532 | type: Sequelize.QueryTypes.BULKUPDATE, | ||
533 | transaction: t | ||
534 | } : undefined | ||
535 | |||
536 | return ActorFollowModel.sequelize.query(query, options) | ||
537 | } | ||
538 | |||
539 | private static listBadActorFollows () { | 521 | private static listBadActorFollows () { |
540 | const query = { | 522 | const query = { |
541 | where: { | 523 | where: { |