1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 19:42:24 +02:00

Optimize AP video captions update

This commit is contained in:
Chocobozzz 2021-06-09 16:22:01 +02:00
parent 4ead40e776
commit 57a0a9cde4
No known key found for this signature in database
GPG key ID: 583A612D890159BE
2 changed files with 35 additions and 9 deletions

View file

@ -75,11 +75,28 @@ export abstract class APVideoAbstractBuilder {
}
protected async insertOrReplaceCaptions (video: MVideoFullLight, t: Transaction) {
const videoCaptionsPromises = getCaptionAttributesFromObject(video, this.videoObject)
.map(a => new VideoCaptionModel(a) as MVideoCaption)
.map(c => VideoCaptionModel.insertOrReplaceLanguage(c, t))
const existingCaptions = await VideoCaptionModel.listVideoCaptions(video.id, t)
await Promise.all(videoCaptionsPromises)
let captionsToCreate = getCaptionAttributesFromObject(video, this.videoObject)
.map(a => new VideoCaptionModel(a) as MVideoCaption)
for (const existingCaption of existingCaptions) {
// Only keep captions that do not already exist
const filtered = captionsToCreate.filter(c => !c.isEqual(existingCaption))
// This caption already exists, we don't need to destroy and create it
if (filtered.length !== captionsToCreate.length) {
captionsToCreate = filtered
continue
}
// Destroy this caption that does not exist anymore
await existingCaption.destroy({ transaction: t })
}
for (const captionToCreate of captionsToCreate) {
await captionToCreate.save({ transaction: t })
}
}
protected async insertOrReplaceLive (video: MVideoFullLight, transaction: Transaction) {