diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-06 12:26:58 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-06 12:26:58 +0100 |
commit | 73471b1a52f242e86364ffb077ea6cadb3b07ae2 (patch) | |
tree | 43dbb7748e281f8d80f15326f489cdea10ec857d /server/models/activitypub | |
parent | c22419dd265c0c7185bf4197a1cb286eb3d8ebc0 (diff) | |
parent | f5305c04aae14467d6f957b713c5a902275cbb89 (diff) | |
download | PeerTube-73471b1a52f242e86364ffb077ea6cadb3b07ae2.tar.gz PeerTube-73471b1a52f242e86364ffb077ea6cadb3b07ae2.tar.zst PeerTube-73471b1a52f242e86364ffb077ea6cadb3b07ae2.zip |
Merge branch 'release/v1.2.0'
Diffstat (limited to 'server/models/activitypub')
-rw-r--r-- | server/models/activitypub/actor-follow.ts | 58 | ||||
-rw-r--r-- | server/models/activitypub/actor.ts | 1 |
2 files changed, 21 insertions, 38 deletions
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts index 0a6935083..796e07a42 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: { |
@@ -323,7 +307,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
323 | }) | 307 | }) |
324 | } | 308 | } |
325 | 309 | ||
326 | static listFollowersForApi (id: number, start: number, count: number, sort: string, search?: string) { | 310 | static listFollowersForApi (actorId: number, start: number, count: number, sort: string, search?: string) { |
327 | const query = { | 311 | const query = { |
328 | distinct: true, | 312 | distinct: true, |
329 | offset: start, | 313 | offset: start, |
@@ -351,7 +335,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
351 | as: 'ActorFollowing', | 335 | as: 'ActorFollowing', |
352 | required: true, | 336 | required: true, |
353 | where: { | 337 | where: { |
354 | id | 338 | id: actorId |
355 | } | 339 | } |
356 | } | 340 | } |
357 | ] | 341 | ] |
@@ -366,7 +350,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
366 | }) | 350 | }) |
367 | } | 351 | } |
368 | 352 | ||
369 | static listSubscriptionsForApi (id: number, start: number, count: number, sort: string) { | 353 | static listSubscriptionsForApi (actorId: number, start: number, count: number, sort: string) { |
370 | const query = { | 354 | const query = { |
371 | attributes: [], | 355 | attributes: [], |
372 | distinct: true, | 356 | distinct: true, |
@@ -374,7 +358,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
374 | limit: count, | 358 | limit: count, |
375 | order: getSort(sort), | 359 | order: getSort(sort), |
376 | where: { | 360 | where: { |
377 | actorId: id | 361 | actorId: actorId |
378 | }, | 362 | }, |
379 | include: [ | 363 | include: [ |
380 | { | 364 | { |
@@ -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: { |
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index 12b83916e..dda57a8ba 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts | |||
@@ -219,6 +219,7 @@ export class ActorModel extends Model<ActorModel> { | |||
219 | name: 'actorId', | 219 | name: 'actorId', |
220 | allowNull: false | 220 | allowNull: false |
221 | }, | 221 | }, |
222 | as: 'ActorFollowings', | ||
222 | onDelete: 'cascade' | 223 | onDelete: 'cascade' |
223 | }) | 224 | }) |
224 | ActorFollowing: ActorFollowModel[] | 225 | ActorFollowing: ActorFollowModel[] |