Fix fk error when generating storyboard

pull/5898/head
Chocobozzz 2023-07-26 09:25:21 +02:00
parent 89b9eab5a7
commit 93fd6f3b18
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 32 additions and 15 deletions

View File

@ -1,10 +1,13 @@
import { Job } from 'bullmq'
import { join } from 'path'
import { retryTransactionWrapper } from '@server/helpers/database-utils'
import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg'
import { generateImageFilename, getImageSize } from '@server/helpers/image-utils'
import { logger, loggerTagsFactory } from '@server/helpers/logger'
import { deleteFileAndCatch } from '@server/helpers/utils'
import { CONFIG } from '@server/initializers/config'
import { STORYBOARD } from '@server/initializers/constants'
import { sequelizeTypescript } from '@server/initializers/database'
import { federateVideoIfNeeded } from '@server/lib/activitypub/videos'
import { VideoPathManager } from '@server/lib/video-path-manager'
import { StoryboardModel } from '@server/models/video/storyboard'
@ -75,25 +78,39 @@ async function processGenerateStoryboard (job: Job): Promise<void> {
const imageSize = await getImageSize(destination)
const existing = await StoryboardModel.loadByVideo(video.id)
if (existing) await existing.destroy()
await retryTransactionWrapper(() => {
return sequelizeTypescript.transaction(async transaction => {
const videoStillExists = await VideoModel.load(video.id, transaction)
if (!videoStillExists) {
logger.info('Video %s does not exist anymore, skipping storyboard generation.', payload.videoUUID, lTags)
deleteFileAndCatch(destination)
return
}
await StoryboardModel.create({
filename,
totalHeight: imageSize.height,
totalWidth: imageSize.width,
spriteHeight: STORYBOARD.SPRITE_SIZE.height,
spriteWidth: STORYBOARD.SPRITE_SIZE.width,
spriteDuration,
videoId: video.id
const existing = await StoryboardModel.loadByVideo(video.id, transaction)
if (existing) await existing.destroy({ transaction })
await StoryboardModel.create({
filename,
totalHeight: imageSize.height,
totalWidth: imageSize.width,
spriteHeight: STORYBOARD.SPRITE_SIZE.height,
spriteWidth: STORYBOARD.SPRITE_SIZE.width,
spriteDuration,
videoId: video.id
}, { transaction })
logger.info('Storyboard generation %s ended for video %s.', destination, video.uuid, lTags)
if (payload.federate) {
await federateVideoIfNeeded(video, false, transaction)
}
})
})
logger.info('Storyboard generation %s ended for video %s.', destination, video.uuid, lTags)
})
if (payload.federate) {
await federateVideoIfNeeded(video, false)
}
} finally {
inputFileMutexReleaser()
}

View File

@ -59,7 +59,7 @@ export class StoryboardModel extends Model<Partial<AttributesOnly<StoryboardMode
@BelongsTo(() => VideoModel, {
foreignKey: {
allowNull: true
allowNull: false
},
onDelete: 'CASCADE'
})