diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-30 11:31:15 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-30 11:31:15 +0100 |
commit | 25ed141c7c7631ef21d8764c1163fbf8a6591391 (patch) | |
tree | 8f556181a3369e7e4938d612d91be0af813e5067 /server/models | |
parent | 5cd80545422bba855cc9a730a2e13cc9d982c34b (diff) | |
download | PeerTube-25ed141c7c7631ef21d8764c1163fbf8a6591391.tar.gz PeerTube-25ed141c7c7631ef21d8764c1163fbf8a6591391.tar.zst PeerTube-25ed141c7c7631ef21d8764c1163fbf8a6591391.zip |
Put activity pub sends inside transactions
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/account/account-follow-interface.ts | 16 | ||||
-rw-r--r-- | server/models/account/account-follow.ts | 16 | ||||
-rw-r--r-- | server/models/account/account-interface.ts | 4 | ||||
-rw-r--r-- | server/models/account/account-video-rate.ts | 2 | ||||
-rw-r--r-- | server/models/account/account.ts | 6 | ||||
-rw-r--r-- | server/models/video/video-channel-share-interface.ts | 5 | ||||
-rw-r--r-- | server/models/video/video-channel-share.ts | 10 | ||||
-rw-r--r-- | server/models/video/video-share-interface.ts | 5 | ||||
-rw-r--r-- | server/models/video/video-share.ts | 10 |
9 files changed, 46 insertions, 28 deletions
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 { | |||
14 | export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountFollowInstance>> | 14 | export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountFollowInstance>> |
15 | export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountFollowInstance>> | 15 | export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountFollowInstance>> |
16 | 16 | ||
17 | export type ListAcceptedFollowerUrlsForApi = (accountId: number[], start?: number, count?: number) => Promise< ResultList<string> > | 17 | export type ListAcceptedFollowerUrlsForApi = ( |
18 | export type ListAcceptedFollowingUrlsForApi = (accountId: number[], start?: number, count?: number) => Promise< ResultList<string> > | 18 | accountId: number[], |
19 | export type ListAcceptedFollowerSharedInboxUrls = (accountId: number[]) => Promise< ResultList<string> > | 19 | t: Sequelize.Transaction, |
20 | start?: number, | ||
21 | count?: number | ||
22 | ) => Promise< ResultList<string> > | ||
23 | export type ListAcceptedFollowingUrlsForApi = ( | ||
24 | accountId: number[], | ||
25 | t: Sequelize.Transaction, | ||
26 | start?: number, | ||
27 | count?: number | ||
28 | ) => Promise< ResultList<string> > | ||
29 | export type ListAcceptedFollowerSharedInboxUrls = (accountId: number[], t: Sequelize.Transaction) => Promise< ResultList<string> > | ||
20 | export type ToFormattedJSON = (this: AccountFollowInstance) => AccountFollow | 30 | export type ToFormattedJSON = (this: AccountFollowInstance) => AccountFollow |
21 | } | 31 | } |
22 | 32 | ||
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: | |||
181 | }) | 181 | }) |
182 | } | 182 | } |
183 | 183 | ||
184 | listAcceptedFollowerUrlsForApi = function (accountIds: number[], start?: number, count?: number) { | 184 | listAcceptedFollowerUrlsForApi = function (accountIds: number[], t: Sequelize.Transaction, start?: number, count?: number) { |
185 | return createListAcceptedFollowForApiQuery('followers', accountIds, start, count) | 185 | return createListAcceptedFollowForApiQuery('followers', accountIds, t, start, count) |
186 | } | 186 | } |
187 | 187 | ||
188 | listAcceptedFollowerSharedInboxUrls = function (accountIds: number[]) { | 188 | listAcceptedFollowerSharedInboxUrls = function (accountIds: number[], t: Sequelize.Transaction) { |
189 | return createListAcceptedFollowForApiQuery('followers', accountIds, undefined, undefined, 'sharedInboxUrl') | 189 | return createListAcceptedFollowForApiQuery('followers', accountIds, t, undefined, undefined, 'sharedInboxUrl') |
190 | } | 190 | } |
191 | 191 | ||
192 | listAcceptedFollowingUrlsForApi = function (accountIds: number[], start?: number, count?: number) { | 192 | listAcceptedFollowingUrlsForApi = function (accountIds: number[], t: Sequelize.Transaction, start?: number, count?: number) { |
193 | return createListAcceptedFollowForApiQuery('following', accountIds, start, count) | 193 | return createListAcceptedFollowForApiQuery('following', accountIds, t, start, count) |
194 | } | 194 | } |
195 | 195 | ||
196 | // ------------------------------ UTILS ------------------------------ | 196 | // ------------------------------ UTILS ------------------------------ |
@@ -198,6 +198,7 @@ listAcceptedFollowingUrlsForApi = function (accountIds: number[], start?: number | |||
198 | async function createListAcceptedFollowForApiQuery ( | 198 | async function createListAcceptedFollowForApiQuery ( |
199 | type: 'followers' | 'following', | 199 | type: 'followers' | 'following', |
200 | accountIds: number[], | 200 | accountIds: number[], |
201 | t: Sequelize.Transaction, | ||
201 | start?: number, | 202 | start?: number, |
202 | count?: number, | 203 | count?: number, |
203 | columnUrl = 'url' | 204 | columnUrl = 'url' |
@@ -227,7 +228,8 @@ async function createListAcceptedFollowForApiQuery ( | |||
227 | 228 | ||
228 | const options = { | 229 | const options = { |
229 | bind: { accountIds }, | 230 | bind: { accountIds }, |
230 | type: Sequelize.QueryTypes.SELECT | 231 | type: Sequelize.QueryTypes.SELECT, |
232 | transaction: t | ||
231 | } | 233 | } |
232 | tasks.push(AccountFollow['sequelize'].query(query, options)) | 234 | tasks.push(AccountFollow['sequelize'].query(query, options)) |
233 | } | 235 | } |
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 { | |||
12 | export type LoadByUrl = (url: string, transaction?: Sequelize.Transaction) => Bluebird<AccountInstance> | 12 | export type LoadByUrl = (url: string, transaction?: Sequelize.Transaction) => Bluebird<AccountInstance> |
13 | export type LoadLocalByName = (name: string) => Bluebird<AccountInstance> | 13 | export type LoadLocalByName = (name: string) => Bluebird<AccountInstance> |
14 | export type LoadByNameAndHost = (name: string, host: string) => Bluebird<AccountInstance> | 14 | export type LoadByNameAndHost = (name: string, host: string) => Bluebird<AccountInstance> |
15 | export type ListByFollowersUrls = (followerUrls: string[], transaction?: Sequelize.Transaction) => Bluebird<AccountInstance[]> | 15 | export type ListByFollowersUrls = (followerUrls: string[], transaction: Sequelize.Transaction) => Bluebird<AccountInstance[]> |
16 | 16 | ||
17 | export type ToActivityPubObject = (this: AccountInstance) => ActivityPubActor | 17 | export type ToActivityPubObject = (this: AccountInstance) => ActivityPubActor |
18 | export type ToFormattedJSON = (this: AccountInstance) => FormattedAccount | 18 | export type ToFormattedJSON = (this: AccountInstance) => FormattedAccount |
19 | export type IsOwned = (this: AccountInstance) => boolean | 19 | export type IsOwned = (this: AccountInstance) => boolean |
20 | export type GetFollowerSharedInboxUrls = (this: AccountInstance) => Bluebird<string[]> | 20 | export type GetFollowerSharedInboxUrls = (this: AccountInstance, t: Sequelize.Transaction) => Bluebird<string[]> |
21 | export type GetFollowingUrl = (this: AccountInstance) => string | 21 | export type GetFollowingUrl = (this: AccountInstance) => string |
22 | export type GetFollowersUrl = (this: AccountInstance) => string | 22 | export type GetFollowersUrl = (this: AccountInstance) => string |
23 | export type GetPublicKeyUrl = (this: AccountInstance) => string | 23 | 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 | |||
28 | { | 28 | { |
29 | indexes: [ | 29 | indexes: [ |
30 | { | 30 | { |
31 | fields: [ 'videoId', 'accountId', 'type' ], | 31 | fields: [ 'videoId', 'accountId' ], |
32 | unique: true | 32 | unique: true |
33 | } | 33 | } |
34 | ] | 34 | ] |
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 { | |||
10 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 10 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
11 | import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers/constants' | 11 | import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers/constants' |
12 | import { sendDeleteAccount } from '../../lib/activitypub/send/send-delete' | 12 | import { sendDeleteAccount } from '../../lib/activitypub/send/send-delete' |
13 | |||
14 | import { addMethodsToModel } from '../utils' | 13 | import { addMethodsToModel } from '../utils' |
15 | import { AccountAttributes, AccountInstance, AccountMethods } from './account-interface' | 14 | import { AccountAttributes, AccountInstance, AccountMethods } from './account-interface' |
16 | 15 | ||
@@ -315,7 +314,7 @@ isOwned = function (this: AccountInstance) { | |||
315 | return this.serverId === null | 314 | return this.serverId === null |
316 | } | 315 | } |
317 | 316 | ||
318 | getFollowerSharedInboxUrls = function (this: AccountInstance) { | 317 | getFollowerSharedInboxUrls = function (this: AccountInstance, t: Sequelize.Transaction) { |
319 | const query: Sequelize.FindOptions<AccountAttributes> = { | 318 | const query: Sequelize.FindOptions<AccountAttributes> = { |
320 | attributes: [ 'sharedInboxUrl' ], | 319 | attributes: [ 'sharedInboxUrl' ], |
321 | include: [ | 320 | include: [ |
@@ -327,7 +326,8 @@ getFollowerSharedInboxUrls = function (this: AccountInstance) { | |||
327 | targetAccountId: this.id | 326 | targetAccountId: this.id |
328 | } | 327 | } |
329 | } | 328 | } |
330 | ] | 329 | ], |
330 | transaction: t | ||
331 | } | 331 | } |
332 | 332 | ||
333 | return Account.findAll(query) | 333 | 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 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import * as Sequelize from 'sequelize' | 2 | import * as Sequelize from 'sequelize' |
3 | import { Transaction } from 'sequelize' | ||
3 | import { AccountInstance } from '../account/account-interface' | 4 | import { AccountInstance } from '../account/account-interface' |
4 | import { VideoChannelInstance } from './video-channel-interface' | 5 | import { VideoChannelInstance } from './video-channel-interface' |
5 | 6 | ||
6 | export namespace VideoChannelShareMethods { | 7 | export namespace VideoChannelShareMethods { |
7 | export type LoadAccountsByShare = (videoChannelId: number) => Bluebird<AccountInstance[]> | 8 | export type LoadAccountsByShare = (videoChannelId: number, t: Transaction) => Bluebird<AccountInstance[]> |
8 | export type Load = (accountId: number, videoId: number) => Bluebird<VideoChannelShareInstance> | 9 | export type Load = (accountId: number, videoId: number, t: Transaction) => Bluebird<VideoChannelShareInstance> |
9 | } | 10 | } |
10 | 11 | ||
11 | export interface VideoChannelShareClass { | 12 | 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) { | |||
52 | }) | 52 | }) |
53 | } | 53 | } |
54 | 54 | ||
55 | load = function (accountId: number, videoChannelId: number) { | 55 | load = function (accountId: number, videoChannelId: number, t: Sequelize.Transaction) { |
56 | return VideoChannelShare.findOne({ | 56 | return VideoChannelShare.findOne({ |
57 | where: { | 57 | where: { |
58 | accountId, | 58 | accountId, |
@@ -61,11 +61,12 @@ load = function (accountId: number, videoChannelId: number) { | |||
61 | include: [ | 61 | include: [ |
62 | VideoChannelShare['sequelize'].models.Account, | 62 | VideoChannelShare['sequelize'].models.Account, |
63 | VideoChannelShare['sequelize'].models.VideoChannel | 63 | VideoChannelShare['sequelize'].models.VideoChannel |
64 | ] | 64 | ], |
65 | transaction: t | ||
65 | }) | 66 | }) |
66 | } | 67 | } |
67 | 68 | ||
68 | loadAccountsByShare = function (videoChannelId: number) { | 69 | loadAccountsByShare = function (videoChannelId: number, t: Sequelize.Transaction) { |
69 | const query = { | 70 | const query = { |
70 | where: { | 71 | where: { |
71 | videoChannelId | 72 | videoChannelId |
@@ -75,7 +76,8 @@ loadAccountsByShare = function (videoChannelId: number) { | |||
75 | model: VideoChannelShare['sequelize'].models.Account, | 76 | model: VideoChannelShare['sequelize'].models.Account, |
76 | required: true | 77 | required: true |
77 | } | 78 | } |
78 | ] | 79 | ], |
80 | transaction: t | ||
79 | } | 81 | } |
80 | 82 | ||
81 | return VideoChannelShare.findAll(query) | 83 | 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 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import * as Sequelize from 'sequelize' | 2 | import * as Sequelize from 'sequelize' |
3 | import { Transaction } from 'sequelize' | ||
3 | import { AccountInstance } from '../account/account-interface' | 4 | import { AccountInstance } from '../account/account-interface' |
4 | import { VideoInstance } from './video-interface' | 5 | import { VideoInstance } from './video-interface' |
5 | 6 | ||
6 | export namespace VideoShareMethods { | 7 | export namespace VideoShareMethods { |
7 | export type LoadAccountsByShare = (videoId: number) => Bluebird<AccountInstance[]> | 8 | export type LoadAccountsByShare = (videoId: number, t: Transaction) => Bluebird<AccountInstance[]> |
8 | export type Load = (accountId: number, videoId: number) => Bluebird<VideoShareInstance> | 9 | export type Load = (accountId: number, videoId: number, t: Transaction) => Bluebird<VideoShareInstance> |
9 | } | 10 | } |
10 | 11 | ||
11 | export interface VideoShareClass { | 12 | 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) { | |||
52 | }) | 52 | }) |
53 | } | 53 | } |
54 | 54 | ||
55 | load = function (accountId: number, videoId: number) { | 55 | load = function (accountId: number, videoId: number, t: Sequelize.Transaction) { |
56 | return VideoShare.findOne({ | 56 | return VideoShare.findOne({ |
57 | where: { | 57 | where: { |
58 | accountId, | 58 | accountId, |
@@ -60,11 +60,12 @@ load = function (accountId: number, videoId: number) { | |||
60 | }, | 60 | }, |
61 | include: [ | 61 | include: [ |
62 | VideoShare['sequelize'].models.Account | 62 | VideoShare['sequelize'].models.Account |
63 | ] | 63 | ], |
64 | transaction: t | ||
64 | }) | 65 | }) |
65 | } | 66 | } |
66 | 67 | ||
67 | loadAccountsByShare = function (videoId: number) { | 68 | loadAccountsByShare = function (videoId: number, t: Sequelize.Transaction) { |
68 | const query = { | 69 | const query = { |
69 | where: { | 70 | where: { |
70 | videoId | 71 | videoId |
@@ -74,7 +75,8 @@ loadAccountsByShare = function (videoId: number) { | |||
74 | model: VideoShare['sequelize'].models.Account, | 75 | model: VideoShare['sequelize'].models.Account, |
75 | required: true | 76 | required: true |
76 | } | 77 | } |
77 | ] | 78 | ], |
79 | transaction: t | ||
78 | } | 80 | } |
79 | 81 | ||
80 | return VideoShare.findAll(query) | 82 | return VideoShare.findAll(query) |