Fix avatar transaction retry
authorChocobozzz <me@florianbigard.com>
Wed, 26 Sep 2018 08:15:50 +0000 (10:15 +0200)
committerChocobozzz <me@florianbigard.com>
Wed, 26 Sep 2018 08:15:50 +0000 (10:15 +0200)
server/controllers/api/video-channel.ts
server/lib/avatar.ts

index ff6bbe44c0b068ba533fbac53cc283a6b01ae7d7..4ca5ba9bcef136ebfdc408ab590d47828a974b6b 100644 (file)
@@ -56,7 +56,7 @@ videoChannelRouter.post('/:nameWithHost/avatar/pick',
   // Check the rights
   asyncMiddleware(videoChannelsUpdateValidator),
   updateAvatarValidator,
-  asyncRetryTransactionMiddleware(updateVideoChannelAvatar)
+  asyncMiddleware(updateVideoChannelAvatar)
 )
 
 videoChannelRouter.put('/:nameWithHost',
index 14f0a05f58829f5d93a175c2e616392ce9cde1ec..4b6bc318579ffeb4cd29ad01c9b1c83591b3779f 100644 (file)
@@ -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
+    })
   })
 }