From 25ed141c7c7631ef21d8764c1163fbf8a6591391 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 30 Nov 2017 11:31:15 +0100 Subject: Put activity pub sends inside transactions --- server/models/account/account-follow-interface.ts | 16 +++++++++++++--- server/models/account/account-follow.ts | 16 +++++++++------- server/models/account/account-interface.ts | 4 ++-- server/models/account/account-video-rate.ts | 2 +- server/models/account/account.ts | 6 +++--- 5 files changed, 28 insertions(+), 16 deletions(-) (limited to 'server/models/account') diff --git a/server/models/account/account-follow-interface.ts b/server/models/account/account-follow-interface.ts index a0d620dd0..7975a46f3 100644 --- a/server/models/account/account-follow-interface.ts +++ b/server/models/account/account-follow-interface.ts @@ -14,9 +14,19 @@ export namespace AccountFollowMethods { export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList> export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList> - export type ListAcceptedFollowerUrlsForApi = (accountId: number[], start?: number, count?: number) => Promise< ResultList > - export type ListAcceptedFollowingUrlsForApi = (accountId: number[], start?: number, count?: number) => Promise< ResultList > - export type ListAcceptedFollowerSharedInboxUrls = (accountId: number[]) => Promise< ResultList > + export type ListAcceptedFollowerUrlsForApi = ( + accountId: number[], + t: Sequelize.Transaction, + start?: number, + count?: number + ) => Promise< ResultList > + export type ListAcceptedFollowingUrlsForApi = ( + accountId: number[], + t: Sequelize.Transaction, + start?: number, + count?: number + ) => Promise< ResultList > + export type ListAcceptedFollowerSharedInboxUrls = (accountId: number[], t: Sequelize.Transaction) => Promise< ResultList > export type ToFormattedJSON = (this: AccountFollowInstance) => AccountFollow } diff --git a/server/models/account/account-follow.ts b/server/models/account/account-follow.ts index 8e35c7d20..724f37baa 100644 --- a/server/models/account/account-follow.ts +++ b/server/models/account/account-follow.ts @@ -181,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 ------------------------------ @@ -198,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' @@ -227,7 +228,8 @@ async function createListAcceptedFollowForApiQuery ( const options = { bind: { accountIds }, - type: Sequelize.QueryTypes.SELECT + type: Sequelize.QueryTypes.SELECT, + transaction: t } tasks.push(AccountFollow['sequelize'].query(query, options)) } diff --git a/server/models/account/account-interface.ts b/server/models/account/account-interface.ts index 6fc98ba45..b369766dc 100644 --- a/server/models/account/account-interface.ts +++ b/server/models/account/account-interface.ts @@ -12,12 +12,12 @@ export namespace AccountMethods { export type LoadByUrl = (url: string, transaction?: Sequelize.Transaction) => Bluebird export type LoadLocalByName = (name: string) => Bluebird export type LoadByNameAndHost = (name: string, host: string) => Bluebird - export type ListByFollowersUrls = (followerUrls: string[], transaction?: Sequelize.Transaction) => Bluebird + export type ListByFollowersUrls = (followerUrls: string[], transaction: Sequelize.Transaction) => Bluebird export type ToActivityPubObject = (this: AccountInstance) => ActivityPubActor export type ToFormattedJSON = (this: AccountInstance) => FormattedAccount export type IsOwned = (this: AccountInstance) => boolean - export type GetFollowerSharedInboxUrls = (this: AccountInstance) => Bluebird + export type GetFollowerSharedInboxUrls = (this: AccountInstance, t: Sequelize.Transaction) => Bluebird export type GetFollowingUrl = (this: AccountInstance) => string export type GetFollowersUrl = (this: AccountInstance) => string export type GetPublicKeyUrl = (this: AccountInstance) => string diff --git a/server/models/account/account-video-rate.ts b/server/models/account/account-video-rate.ts index 7f7c97606..d92834bbb 100644 --- a/server/models/account/account-video-rate.ts +++ b/server/models/account/account-video-rate.ts @@ -28,7 +28,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da { indexes: [ { - fields: [ 'videoId', 'accountId', 'type' ], + fields: [ 'videoId', 'accountId' ], unique: true } ] diff --git a/server/models/account/account.ts b/server/models/account/account.ts index c721656cb..61a88524c 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts @@ -10,7 +10,6 @@ import { import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers/constants' import { sendDeleteAccount } from '../../lib/activitypub/send/send-delete' - import { addMethodsToModel } from '../utils' import { AccountAttributes, AccountInstance, AccountMethods } from './account-interface' @@ -315,7 +314,7 @@ isOwned = function (this: AccountInstance) { return this.serverId === null } -getFollowerSharedInboxUrls = function (this: AccountInstance) { +getFollowerSharedInboxUrls = function (this: AccountInstance, t: Sequelize.Transaction) { const query: Sequelize.FindOptions = { attributes: [ 'sharedInboxUrl' ], include: [ @@ -327,7 +326,8 @@ getFollowerSharedInboxUrls = function (this: AccountInstance) { targetAccountId: this.id } } - ] + ], + transaction: t } return Account.findAll(query) -- cgit v1.2.3