Try playlist rebuild transaction if needed

pull/5250/head
Chocobozzz 2022-09-09 12:05:35 +02:00
parent edacb64033
commit d9dd51aec7
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 3 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import { map } from 'bluebird' import { map } from 'bluebird'
import { isArray } from '@server/helpers/custom-validators/misc' import { isArray } from '@server/helpers/custom-validators/misc'
import { retryTransactionWrapper } from '@server/helpers/database-utils'
import { logger, loggerTagsFactory } from '@server/helpers/logger' import { logger, loggerTagsFactory } from '@server/helpers/logger'
import { CRAWL_REQUEST_CONCURRENCY } from '@server/initializers/constants' import { CRAWL_REQUEST_CONCURRENCY } from '@server/initializers/constants'
import { sequelizeTypescript } from '@server/initializers/database' import { sequelizeTypescript } from '@server/initializers/database'
@ -124,13 +125,13 @@ async function updatePlaylistThumbnail (playlistObject: PlaylistObject, playlist
async function rebuildVideoPlaylistElements (elementUrls: string[], playlist: MVideoPlaylist) { async function rebuildVideoPlaylistElements (elementUrls: string[], playlist: MVideoPlaylist) {
const elementsToCreate = await buildElementsDBAttributes(elementUrls, playlist) const elementsToCreate = await buildElementsDBAttributes(elementUrls, playlist)
await sequelizeTypescript.transaction(async t => { await retryTransactionWrapper(() => sequelizeTypescript.transaction(async t => {
await VideoPlaylistElementModel.deleteAllOf(playlist.id, t) await VideoPlaylistElementModel.deleteAllOf(playlist.id, t)
for (const element of elementsToCreate) { for (const element of elementsToCreate) {
await VideoPlaylistElementModel.create(element, { transaction: t }) await VideoPlaylistElementModel.create(element, { transaction: t })
} }
}) }))
logger.info('Rebuilt playlist %s with %s elements.', playlist.url, elementsToCreate.length, lTags(playlist.uuid, playlist.url)) logger.info('Rebuilt playlist %s with %s elements.', playlist.url, elementsToCreate.length, lTags(playlist.uuid, playlist.url))