]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/account/account-follow.ts
Put activity pub sends inside transactions
[github/Chocobozzz/PeerTube.git] / server / models / account / account-follow.ts
index 34ba3f8dbcb12649a74ee7b373f16a524fa72083..724f37baa6b6038815611ab1d8f5cf652f70e8b0 100644 (file)
@@ -93,7 +93,7 @@ toFormattedJSON = function (this: AccountFollowInstance) {
   return json
 }
 
-loadByAccountAndTarget = function (accountId: number, targetAccountId: number) {
+loadByAccountAndTarget = function (accountId: number, targetAccountId: number, t?: Sequelize.Transaction) {
   const query = {
     where: {
       accountId,
@@ -110,7 +110,8 @@ loadByAccountAndTarget = function (accountId: number, targetAccountId: number) {
         required: true,
         as: 'AccountFollowing'
       }
-    ]
+    ],
+    transaction: t
   }
 
   return AccountFollow.findOne(query)
@@ -180,16 +181,16 @@ listFollowersForApi = function (id: number, start: number, count: number, sort:
   })
 }
 
-listAcceptedFollowerUrlsForApi = function (accountIds: number[], start?: number, count?: number) {
-  return createListAcceptedFollowForApiQuery('followers', accountIds, start, count)
+listAcceptedFollowerUrlsForApi = function (accountIds: number[], t: Sequelize.Transaction, start?: number, count?: number) {
+  return createListAcceptedFollowForApiQuery('followers', accountIds, t, start, count)
 }
 
-listAcceptedFollowerSharedInboxUrls = function (accountIds: number[]) {
-  return createListAcceptedFollowForApiQuery('followers', accountIds, undefined, undefined, 'sharedInboxUrl')
+listAcceptedFollowerSharedInboxUrls = function (accountIds: number[], t: Sequelize.Transaction) {
+  return createListAcceptedFollowForApiQuery('followers', accountIds, t, undefined, undefined, 'sharedInboxUrl')
 }
 
-listAcceptedFollowingUrlsForApi = function (accountIds: number[], start?: number, count?: number) {
-  return createListAcceptedFollowForApiQuery('following', accountIds, start, count)
+listAcceptedFollowingUrlsForApi = function (accountIds: number[], t: Sequelize.Transaction, start?: number, count?: number) {
+  return createListAcceptedFollowForApiQuery('following', accountIds, t, start, count)
 }
 
 // ------------------------------ UTILS ------------------------------
@@ -197,6 +198,7 @@ listAcceptedFollowingUrlsForApi = function (accountIds: number[], start?: number
 async function createListAcceptedFollowForApiQuery (
   type: 'followers' | 'following',
   accountIds: number[],
+  t: Sequelize.Transaction,
   start?: number,
   count?: number,
   columnUrl = 'url'
@@ -221,12 +223,13 @@ async function createListAcceptedFollowForApiQuery (
       'INNER JOIN "Accounts" AS "Follows" ON "AccountFollows"."' + secondJoin + '" = "Follows"."id" ' +
       'WHERE "Accounts"."id" = ANY ($accountIds) AND "AccountFollows"."state" = \'accepted\' '
 
-    if (start !== undefined) query += 'LIMIT ' + start
-    if (count !== undefined) query += ', ' + count
+    if (count !== undefined) query += 'LIMIT ' + count
+    if (start !== undefined) query += ' OFFSET ' + start
 
     const options = {
       bind: { accountIds },
-      type: Sequelize.QueryTypes.SELECT
+      type: Sequelize.QueryTypes.SELECT,
+      transaction: t
     }
     tasks.push(AccountFollow['sequelize'].query(query, options))
   }