diff options
author | Chocobozzz <me@florianbigard.com> | 2021-06-09 16:22:01 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-06-09 16:22:01 +0200 |
commit | 57a0a9cde4760314d9b1fdd920e0b4a180a9925e (patch) | |
tree | 97274952d05fa4ce88ed1629e0977c797ba7dd35 /server/lib | |
parent | 4ead40e7766f5964ecd9a11766ff56b95090fe1c (diff) | |
download | PeerTube-57a0a9cde4760314d9b1fdd920e0b4a180a9925e.tar.gz PeerTube-57a0a9cde4760314d9b1fdd920e0b4a180a9925e.tar.zst PeerTube-57a0a9cde4760314d9b1fdd920e0b4a180a9925e.zip |
Optimize AP video captions update
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/videos/shared/abstract-builder.ts | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/server/lib/activitypub/videos/shared/abstract-builder.ts b/server/lib/activitypub/videos/shared/abstract-builder.ts index 22280fce1..e89c94bcd 100644 --- a/server/lib/activitypub/videos/shared/abstract-builder.ts +++ b/server/lib/activitypub/videos/shared/abstract-builder.ts | |||
@@ -75,11 +75,28 @@ export abstract class APVideoAbstractBuilder { | |||
75 | } | 75 | } |
76 | 76 | ||
77 | protected async insertOrReplaceCaptions (video: MVideoFullLight, t: Transaction) { | 77 | protected async insertOrReplaceCaptions (video: MVideoFullLight, t: Transaction) { |
78 | const videoCaptionsPromises = getCaptionAttributesFromObject(video, this.videoObject) | 78 | const existingCaptions = await VideoCaptionModel.listVideoCaptions(video.id, t) |
79 | .map(a => new VideoCaptionModel(a) as MVideoCaption) | ||
80 | .map(c => VideoCaptionModel.insertOrReplaceLanguage(c, t)) | ||
81 | 79 | ||
82 | await Promise.all(videoCaptionsPromises) | 80 | let captionsToCreate = getCaptionAttributesFromObject(video, this.videoObject) |
81 | .map(a => new VideoCaptionModel(a) as MVideoCaption) | ||
82 | |||
83 | for (const existingCaption of existingCaptions) { | ||
84 | // Only keep captions that do not already exist | ||
85 | const filtered = captionsToCreate.filter(c => !c.isEqual(existingCaption)) | ||
86 | |||
87 | // This caption already exists, we don't need to destroy and create it | ||
88 | if (filtered.length !== captionsToCreate.length) { | ||
89 | captionsToCreate = filtered | ||
90 | continue | ||
91 | } | ||
92 | |||
93 | // Destroy this caption that does not exist anymore | ||
94 | await existingCaption.destroy({ transaction: t }) | ||
95 | } | ||
96 | |||
97 | for (const captionToCreate of captionsToCreate) { | ||
98 | await captionToCreate.save({ transaction: t }) | ||
99 | } | ||
83 | } | 100 | } |
84 | 101 | ||
85 | protected async insertOrReplaceLive (video: MVideoFullLight, transaction: Transaction) { | 102 | protected async insertOrReplaceLive (video: MVideoFullLight, transaction: Transaction) { |