]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/activitypub/actor-follow.ts
Add audit logs in various modules
[github/Chocobozzz/PeerTube.git] / server / models / activitypub / actor-follow.ts
index d3c438626ad35a58463ad7f64443c6be44780654..adec5e92b894bd89b07450dd5adefcd087b76edb 100644 (file)
@@ -111,19 +111,19 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
     if (numberOfActorFollowsRemoved) logger.info('Removed bad %d actor follows.', numberOfActorFollowsRemoved)
   }
 
-  static updateActorFollowsScore (goodInboxes: string[], badInboxes: string[], t: Sequelize.Transaction) {
+  static updateActorFollowsScore (goodInboxes: string[], badInboxes: string[], t: Sequelize.Transaction | undefined) {
     if (goodInboxes.length === 0 && badInboxes.length === 0) return
 
     logger.info('Updating %d good actor follows and %d bad actor follows scores.', goodInboxes.length, badInboxes.length)
 
     if (goodInboxes.length !== 0) {
       ActorFollowModel.incrementScores(goodInboxes, ACTOR_FOLLOW_SCORE.BONUS, t)
-        .catch(err => logger.error('Cannot increment scores of good actor follows.', err))
+        .catch(err => logger.error('Cannot increment scores of good actor follows.', { err }))
     }
 
     if (badInboxes.length !== 0) {
       ActorFollowModel.incrementScores(badInboxes, ACTOR_FOLLOW_SCORE.PENALTY, t)
-        .catch(err => logger.error('Cannot decrement scores of bad actor follows.', err))
+        .catch(err => logger.error('Cannot decrement scores of bad actor follows.', { err }))
     }
   }
 
@@ -335,8 +335,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
       tasks.push(ActorFollowModel.sequelize.query(query, options))
     }
 
-    const [ followers, [ { total } ] ] = await
-    Promise.all(tasks)
+    const [ followers, [ { total } ] ] = await Promise.all(tasks)
     const urls: string[] = followers.map(f => f.url)
 
     return {
@@ -345,7 +344,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
     }
   }
 
-  private static incrementScores (inboxUrls: string[], value: number, t: Sequelize.Transaction) {
+  private static incrementScores (inboxUrls: string[], value: number, t: Sequelize.Transaction | undefined) {
     const inboxUrlsString = inboxUrls.map(url => `'${url}'`).join(',')
 
     const query = `UPDATE "actorFollow" SET "score" = LEAST("score" + ${value}, ${ACTOR_FOLLOW_SCORE.MAX}) ` +
@@ -355,10 +354,10 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
         'WHERE "actor"."inboxUrl" IN (' + inboxUrlsString + ') OR "actor"."sharedInboxUrl" IN (' + inboxUrlsString + ')' +
       ')'
 
-    const options = {
+    const options = t ? {
       type: Sequelize.QueryTypes.BULKUPDATE,
       transaction: t
-    }
+    } : undefined
 
     return ActorFollowModel.sequelize.query(query, options)
   }