aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/videos
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-08 17:29:45 +0200
committerChocobozzz <me@florianbigard.com>2021-06-08 17:41:48 +0200
commit28dfb44b145c537aba07ae73cb1287f25532022a (patch)
tree4aee64a049b396c8689f29e5ca8a8094dd3baf54 /server/lib/activitypub/videos
parent75e12406e271e3aaf1f7c394a63ce570091db480 (diff)
downloadPeerTube-28dfb44b145c537aba07ae73cb1287f25532022a.tar.gz
PeerTube-28dfb44b145c537aba07ae73cb1287f25532022a.tar.zst
PeerTube-28dfb44b145c537aba07ae73cb1287f25532022a.zip
Try to speed up AP update transaction
Diffstat (limited to 'server/lib/activitypub/videos')
-rw-r--r--server/lib/activitypub/videos/shared/abstract-builder.ts2
-rw-r--r--server/lib/activitypub/videos/shared/trackers.ts2
-rw-r--r--server/lib/activitypub/videos/updater.ts33
3 files changed, 20 insertions, 17 deletions
diff --git a/server/lib/activitypub/videos/shared/abstract-builder.ts b/server/lib/activitypub/videos/shared/abstract-builder.ts
index 0b58ddb33..22280fce1 100644
--- a/server/lib/activitypub/videos/shared/abstract-builder.ts
+++ b/server/lib/activitypub/videos/shared/abstract-builder.ts
@@ -49,7 +49,7 @@ export abstract class APVideoAbstractBuilder {
49 }) 49 })
50 } 50 }
51 51
52 protected async setPreview (video: MVideoFullLight, t: Transaction) { 52 protected async setPreview (video: MVideoFullLight, t?: Transaction) {
53 // Don't fetch the preview that could be big, create a placeholder instead 53 // Don't fetch the preview that could be big, create a placeholder instead
54 const previewIcon = getPreviewFromIcons(this.videoObject) 54 const previewIcon = getPreviewFromIcons(this.videoObject)
55 if (!previewIcon) return 55 if (!previewIcon) return
diff --git a/server/lib/activitypub/videos/shared/trackers.ts b/server/lib/activitypub/videos/shared/trackers.ts
index fcb2a5091..1c5fc4f84 100644
--- a/server/lib/activitypub/videos/shared/trackers.ts
+++ b/server/lib/activitypub/videos/shared/trackers.ts
@@ -28,7 +28,7 @@ function getTrackerUrls (object: VideoObject, video: MVideoWithHost) {
28async function setVideoTrackers (options: { 28async function setVideoTrackers (options: {
29 video: MVideo 29 video: MVideo
30 trackers: string[] 30 trackers: string[]
31 transaction?: Transaction 31 transaction: Transaction
32}) { 32}) {
33 const { video, trackers, transaction } = options 33 const { video, trackers, transaction } = options
34 34
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 @@
1import { Transaction } from 'sequelize/types' 1import { Transaction } from 'sequelize/types'
2import { resetSequelizeInstance } from '@server/helpers/database-utils' 2import { resetSequelizeInstance, runInReadCommittedTransaction } from '@server/helpers/database-utils'
3import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger' 3import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger'
4import { sequelizeTypescript } from '@server/initializers/database'
5import { Notifier } from '@server/lib/notifier' 4import { Notifier } from '@server/lib/notifier'
6import { PeerTubeSocket } from '@server/lib/peertube-socket' 5import { PeerTubeSocket } from '@server/lib/peertube-socket'
7import { autoBlacklistVideoIfNeeded } from '@server/lib/video-blacklist' 6import { 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