diff options
author | Chocobozzz <me@florianbigard.com> | 2021-06-15 09:17:19 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-06-15 10:40:06 +0200 |
commit | eae0365b5c5468e51e9795b0e894815ebda86b4a (patch) | |
tree | 5da54b28c94d43d1715a0c69e35eb1cf3a1a959d /server/models | |
parent | 51f636ad0f928bb94069c9143e38df0518f6e4a7 (diff) | |
download | PeerTube-eae0365b5c5468e51e9795b0e894815ebda86b4a.tar.gz PeerTube-eae0365b5c5468e51e9795b0e894815ebda86b4a.tar.zst PeerTube-eae0365b5c5468e51e9795b0e894815ebda86b4a.zip |
Fix missing transactions
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/server/server.ts | 6 | ||||
-rw-r--r-- | server/models/video/video-caption.ts | 10 | ||||
-rw-r--r-- | server/models/video/video-channel.ts | 4 | ||||
-rw-r--r-- | server/models/video/video-comment.ts | 6 |
4 files changed, 17 insertions, 9 deletions
diff --git a/server/models/server/server.ts b/server/models/server/server.ts index 25d9924fb..0d3c092e0 100644 --- a/server/models/server/server.ts +++ b/server/models/server/server.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | import { Transaction } from 'sequelize' | ||
1 | import { AllowNull, Column, CreatedAt, Default, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, Column, CreatedAt, Default, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { MServer, MServerFormattable } from '@server/types/models/server' | 3 | import { MServer, MServerFormattable } from '@server/types/models/server' |
3 | import { AttributesOnly } from '@shared/core-utils' | 4 | import { AttributesOnly } from '@shared/core-utils' |
@@ -51,11 +52,12 @@ export class ServerModel extends Model<Partial<AttributesOnly<ServerModel>>> { | |||
51 | }) | 52 | }) |
52 | BlockedByAccounts: ServerBlocklistModel[] | 53 | BlockedByAccounts: ServerBlocklistModel[] |
53 | 54 | ||
54 | static load (id: number): Promise<MServer> { | 55 | static load (id: number, transaction?: Transaction): Promise<MServer> { |
55 | const query = { | 56 | const query = { |
56 | where: { | 57 | where: { |
57 | id | 58 | id |
58 | } | 59 | }, |
60 | transaction | ||
59 | } | 61 | } |
60 | 62 | ||
61 | return ServerModel.findOne(query) | 63 | return ServerModel.findOne(query) |
diff --git a/server/models/video/video-caption.ts b/server/models/video/video-caption.ts index bbda0f3ee..5ec944b9e 100644 --- a/server/models/video/video-caption.ts +++ b/server/models/video/video-caption.ts | |||
@@ -91,9 +91,9 @@ export class VideoCaptionModel extends Model<Partial<AttributesOnly<VideoCaption | |||
91 | Video: VideoModel | 91 | Video: VideoModel |
92 | 92 | ||
93 | @BeforeDestroy | 93 | @BeforeDestroy |
94 | static async removeFiles (instance: VideoCaptionModel) { | 94 | static async removeFiles (instance: VideoCaptionModel, options) { |
95 | if (!instance.Video) { | 95 | if (!instance.Video) { |
96 | instance.Video = await instance.$get('Video') | 96 | instance.Video = await instance.$get('Video', { transaction: options.transaction }) |
97 | } | 97 | } |
98 | 98 | ||
99 | if (instance.isOwned()) { | 99 | if (instance.isOwned()) { |
@@ -113,8 +113,7 @@ export class VideoCaptionModel extends Model<Partial<AttributesOnly<VideoCaption | |||
113 | const videoInclude = { | 113 | const videoInclude = { |
114 | model: VideoModel.unscoped(), | 114 | model: VideoModel.unscoped(), |
115 | attributes: [ 'id', 'remote', 'uuid' ], | 115 | attributes: [ 'id', 'remote', 'uuid' ], |
116 | where: buildWhereIdOrUUID(videoId), | 116 | where: buildWhereIdOrUUID(videoId) |
117 | transaction | ||
118 | } | 117 | } |
119 | 118 | ||
120 | const query = { | 119 | const query = { |
@@ -123,7 +122,8 @@ export class VideoCaptionModel extends Model<Partial<AttributesOnly<VideoCaption | |||
123 | }, | 122 | }, |
124 | include: [ | 123 | include: [ |
125 | videoInclude | 124 | videoInclude |
126 | ] | 125 | ], |
126 | transaction | ||
127 | } | 127 | } |
128 | 128 | ||
129 | return VideoCaptionModel.findOne(query) | 129 | return VideoCaptionModel.findOne(query) |
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 8c4357009..33749ea70 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts | |||
@@ -522,10 +522,10 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"` | |||
522 | }) | 522 | }) |
523 | } | 523 | } |
524 | 524 | ||
525 | static loadAndPopulateAccount (id: number): Promise<MChannelBannerAccountDefault> { | 525 | static loadAndPopulateAccount (id: number, transaction?: Transaction): Promise<MChannelBannerAccountDefault> { |
526 | return VideoChannelModel.unscoped() | 526 | return VideoChannelModel.unscoped() |
527 | .scope([ ScopeNames.WITH_ACTOR_BANNER, ScopeNames.WITH_ACCOUNT ]) | 527 | .scope([ ScopeNames.WITH_ACTOR_BANNER, ScopeNames.WITH_ACCOUNT ]) |
528 | .findByPk(id) | 528 | .findByPk(id, { transaction }) |
529 | } | 529 | } |
530 | 530 | ||
531 | static loadByUrlAndPopulateAccount (url: string): Promise<MChannelBannerAccountDefault> { | 531 | static loadByUrlAndPopulateAccount (url: string): Promise<MChannelBannerAccountDefault> { |
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index e1faf2b9a..e933989ae 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts | |||
@@ -739,6 +739,12 @@ export class VideoCommentModel extends Model<Partial<AttributesOnly<VideoComment | |||
739 | return this.Account.isOwned() | 739 | return this.Account.isOwned() |
740 | } | 740 | } |
741 | 741 | ||
742 | markAsDeleted () { | ||
743 | this.text = '' | ||
744 | this.deletedAt = new Date() | ||
745 | this.accountId = null | ||
746 | } | ||
747 | |||
742 | isDeleted () { | 748 | isDeleted () { |
743 | return this.deletedAt !== null | 749 | return this.deletedAt !== null |
744 | } | 750 | } |