From 4a534352ad046ca804f1f58ef5afb6e366e202b8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 26 Sep 2018 10:15:50 +0200 Subject: [PATCH] Fix avatar transaction retry --- server/controllers/api/video-channel.ts | 2 +- server/lib/avatar.ts | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index ff6bbe44c..4ca5ba9bc 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts @@ -56,7 +56,7 @@ videoChannelRouter.post('/:nameWithHost/avatar/pick', // Check the rights asyncMiddleware(videoChannelsUpdateValidator), updateAvatarValidator, - asyncRetryTransactionMiddleware(updateVideoChannelAvatar) + asyncMiddleware(updateVideoChannelAvatar) ) videoChannelRouter.put('/:nameWithHost', diff --git a/server/lib/avatar.ts b/server/lib/avatar.ts index 14f0a05f5..4b6bc3185 100644 --- a/server/lib/avatar.ts +++ b/server/lib/avatar.ts @@ -6,6 +6,7 @@ import { processImage } from '../helpers/image-utils' import { AccountModel } from '../models/account/account' import { VideoChannelModel } from '../models/video/video-channel' import { extname, join } from 'path' +import { retryTransactionWrapper } from '../helpers/database-utils' async function updateActorAvatarFile (avatarPhysicalFile: Express.Multer.File, accountOrChannel: AccountModel | VideoChannelModel) { const extension = extname(avatarPhysicalFile.filename) @@ -13,13 +14,15 @@ async function updateActorAvatarFile (avatarPhysicalFile: Express.Multer.File, a const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName) await processImage(avatarPhysicalFile, destination, AVATARS_SIZE) - return sequelizeTypescript.transaction(async t => { - const updatedActor = await updateActorAvatarInstance(accountOrChannel.Actor, avatarName, t) - await updatedActor.save({ transaction: t }) + return retryTransactionWrapper(() => { + return sequelizeTypescript.transaction(async t => { + const updatedActor = await updateActorAvatarInstance(accountOrChannel.Actor, avatarName, t) + await updatedActor.save({ transaction: t }) - await sendUpdateActor(accountOrChannel, t) + await sendUpdateActor(accountOrChannel, t) - return updatedActor.Avatar + return updatedActor.Avatar + }) }) } -- 2.25.1