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 +++--- server/models/video/video-channel-share-interface.ts | 5 +++-- server/models/video/video-channel-share.ts | 10 ++++++---- server/models/video/video-share-interface.ts | 5 +++-- server/models/video/video-share.ts | 10 ++++++---- 9 files changed, 46 insertions(+), 28 deletions(-) (limited to 'server/models') 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) diff --git a/server/models/video/video-channel-share-interface.ts b/server/models/video/video-channel-share-interface.ts index bcb3a0e24..0482e8297 100644 --- a/server/models/video/video-channel-share-interface.ts +++ b/server/models/video/video-channel-share-interface.ts @@ -1,11 +1,12 @@ import * as Bluebird from 'bluebird' import * as Sequelize from 'sequelize' +import { Transaction } from 'sequelize' import { AccountInstance } from '../account/account-interface' import { VideoChannelInstance } from './video-channel-interface' export namespace VideoChannelShareMethods { - export type LoadAccountsByShare = (videoChannelId: number) => Bluebird - export type Load = (accountId: number, videoId: number) => Bluebird + export type LoadAccountsByShare = (videoChannelId: number, t: Transaction) => Bluebird + export type Load = (accountId: number, videoId: number, t: Transaction) => Bluebird } export interface VideoChannelShareClass { diff --git a/server/models/video/video-channel-share.ts b/server/models/video/video-channel-share.ts index e47c0dae7..2e9b658a3 100644 --- a/server/models/video/video-channel-share.ts +++ b/server/models/video/video-channel-share.ts @@ -52,7 +52,7 @@ function associate (models) { }) } -load = function (accountId: number, videoChannelId: number) { +load = function (accountId: number, videoChannelId: number, t: Sequelize.Transaction) { return VideoChannelShare.findOne({ where: { accountId, @@ -61,11 +61,12 @@ load = function (accountId: number, videoChannelId: number) { include: [ VideoChannelShare['sequelize'].models.Account, VideoChannelShare['sequelize'].models.VideoChannel - ] + ], + transaction: t }) } -loadAccountsByShare = function (videoChannelId: number) { +loadAccountsByShare = function (videoChannelId: number, t: Sequelize.Transaction) { const query = { where: { videoChannelId @@ -75,7 +76,8 @@ loadAccountsByShare = function (videoChannelId: number) { model: VideoChannelShare['sequelize'].models.Account, required: true } - ] + ], + transaction: t } return VideoChannelShare.findAll(query) diff --git a/server/models/video/video-share-interface.ts b/server/models/video/video-share-interface.ts index ad23444b6..8ad10e095 100644 --- a/server/models/video/video-share-interface.ts +++ b/server/models/video/video-share-interface.ts @@ -1,11 +1,12 @@ import * as Bluebird from 'bluebird' import * as Sequelize from 'sequelize' +import { Transaction } from 'sequelize' import { AccountInstance } from '../account/account-interface' import { VideoInstance } from './video-interface' export namespace VideoShareMethods { - export type LoadAccountsByShare = (videoId: number) => Bluebird - export type Load = (accountId: number, videoId: number) => Bluebird + export type LoadAccountsByShare = (videoId: number, t: Transaction) => Bluebird + export type Load = (accountId: number, videoId: number, t: Transaction) => Bluebird } export interface VideoShareClass { diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts index fe5d56d42..37e405fa9 100644 --- a/server/models/video/video-share.ts +++ b/server/models/video/video-share.ts @@ -52,7 +52,7 @@ function associate (models) { }) } -load = function (accountId: number, videoId: number) { +load = function (accountId: number, videoId: number, t: Sequelize.Transaction) { return VideoShare.findOne({ where: { accountId, @@ -60,11 +60,12 @@ load = function (accountId: number, videoId: number) { }, include: [ VideoShare['sequelize'].models.Account - ] + ], + transaction: t }) } -loadAccountsByShare = function (videoId: number) { +loadAccountsByShare = function (videoId: number, t: Sequelize.Transaction) { const query = { where: { videoId @@ -74,7 +75,8 @@ loadAccountsByShare = function (videoId: number) { model: VideoShare['sequelize'].models.Account, required: true } - ] + ], + transaction: t } return VideoShare.findAll(query) -- cgit v1.2.3