diff options
Diffstat (limited to 'server/lib/activitypub/videos/updater.ts')
-rw-r--r-- | server/lib/activitypub/videos/updater.ts | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/server/lib/activitypub/videos/updater.ts b/server/lib/activitypub/videos/updater.ts index 3339611fc..e17e5fdc2 100644 --- a/server/lib/activitypub/videos/updater.ts +++ b/server/lib/activitypub/videos/updater.ts | |||
@@ -1,7 +1,6 @@ | |||
1 | import { Transaction } from 'sequelize/types' | 1 | import { Transaction } from 'sequelize/types' |
2 | import { resetSequelizeInstance } from '@server/helpers/database-utils' | 2 | import { resetSequelizeInstance, runInReadCommittedTransaction } from '@server/helpers/database-utils' |
3 | import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger' | 3 | import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger' |
4 | import { sequelizeTypescript } from '@server/initializers/database' | ||
5 | import { Notifier } from '@server/lib/notifier' | 4 | import { Notifier } from '@server/lib/notifier' |
6 | import { PeerTubeSocket } from '@server/lib/peertube-socket' | 5 | import { PeerTubeSocket } from '@server/lib/peertube-socket' |
7 | import { autoBlacklistVideoIfNeeded } from '@server/lib/video-blacklist' | 6 | import { autoBlacklistVideoIfNeeded } from '@server/lib/video-blacklist' |
@@ -48,24 +47,26 @@ export class APVideoUpdater extends APVideoAbstractBuilder { | |||
48 | 47 | ||
49 | const thumbnailModel = await this.tryToGenerateThumbnail(this.video) | 48 | const thumbnailModel = await this.tryToGenerateThumbnail(this.video) |
50 | 49 | ||
51 | const videoUpdated = await sequelizeTypescript.transaction(async t => { | 50 | this.checkChannelUpdateOrThrow(channelActor) |
52 | this.checkChannelUpdateOrThrow(channelActor) | ||
53 | 51 | ||
54 | const videoUpdated = await this.updateVideo(channelActor.VideoChannel, t, overrideTo) | 52 | const videoUpdated = await this.updateVideo(channelActor.VideoChannel, undefined, overrideTo) |
55 | 53 | ||
56 | if (thumbnailModel) await videoUpdated.addAndSaveThumbnail(thumbnailModel, t) | 54 | if (thumbnailModel) await videoUpdated.addAndSaveThumbnail(thumbnailModel) |
57 | 55 | ||
58 | await this.setPreview(videoUpdated, t) | 56 | await runInReadCommittedTransaction(async t => { |
59 | await this.setWebTorrentFiles(videoUpdated, t) | 57 | await this.setWebTorrentFiles(videoUpdated, t) |
60 | await this.setStreamingPlaylists(videoUpdated, t) | 58 | await this.setStreamingPlaylists(videoUpdated, t) |
61 | await this.setTags(videoUpdated, t) | ||
62 | await this.setTrackers(videoUpdated, t) | ||
63 | await this.setCaptions(videoUpdated, t) | ||
64 | await this.setOrDeleteLive(videoUpdated, t) | ||
65 | |||
66 | return videoUpdated | ||
67 | }) | 59 | }) |
68 | 60 | ||
61 | await Promise.all([ | ||
62 | runInReadCommittedTransaction(t => this.setTags(videoUpdated, t)), | ||
63 | runInReadCommittedTransaction(t => this.setTrackers(videoUpdated, t)), | ||
64 | this.setOrDeleteLive(videoUpdated), | ||
65 | this.setPreview(videoUpdated) | ||
66 | ]) | ||
67 | |||
68 | await runInReadCommittedTransaction(t => this.setCaptions(videoUpdated, t)) | ||
69 | |||
69 | await autoBlacklistVideoIfNeeded({ | 70 | await autoBlacklistVideoIfNeeded({ |
70 | video: videoUpdated, | 71 | video: videoUpdated, |
71 | user: undefined, | 72 | user: undefined, |
@@ -103,7 +104,7 @@ export class APVideoUpdater extends APVideoAbstractBuilder { | |||
103 | } | 104 | } |
104 | } | 105 | } |
105 | 106 | ||
106 | private updateVideo (channel: MChannelId, transaction: Transaction, overrideTo?: string[]) { | 107 | private updateVideo (channel: MChannelId, transaction?: Transaction, overrideTo?: string[]) { |
107 | const to = overrideTo || this.videoObject.to | 108 | const to = overrideTo || this.videoObject.to |
108 | const videoData = getVideoAttributesFromObject(channel, this.videoObject, to) | 109 | const videoData = getVideoAttributesFromObject(channel, this.videoObject, to) |
109 | this.video.name = videoData.name | 110 | this.video.name = videoData.name |
@@ -140,7 +141,9 @@ export class APVideoUpdater extends APVideoAbstractBuilder { | |||
140 | await this.insertOrReplaceCaptions(videoUpdated, t) | 141 | await this.insertOrReplaceCaptions(videoUpdated, t) |
141 | } | 142 | } |
142 | 143 | ||
143 | private async setOrDeleteLive (videoUpdated: MVideoFullLight, transaction: Transaction) { | 144 | private async setOrDeleteLive (videoUpdated: MVideoFullLight, transaction?: Transaction) { |
145 | if (!this.video.isLive) return | ||
146 | |||
144 | if (this.video.isLive) return this.insertOrReplaceLive(videoUpdated, transaction) | 147 | if (this.video.isLive) return this.insertOrReplaceLive(videoUpdated, transaction) |
145 | 148 | ||
146 | // Delete existing live if it exists | 149 | // Delete existing live if it exists |