aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-09-26 10:15:50 +0200
committerChocobozzz <me@florianbigard.com>2018-09-26 10:15:50 +0200
commit4a534352ad046ca804f1f58ef5afb6e366e202b8 (patch)
treeb6fab0e840a466aa61b094ae7019217a7db1eb92
parent39ba2e8e3a71961cd0087c57d25905f6a97a6b69 (diff)
downloadPeerTube-4a534352ad046ca804f1f58ef5afb6e366e202b8.tar.gz
PeerTube-4a534352ad046ca804f1f58ef5afb6e366e202b8.tar.zst
PeerTube-4a534352ad046ca804f1f58ef5afb6e366e202b8.zip
Fix avatar transaction retry
-rw-r--r--server/controllers/api/video-channel.ts2
-rw-r--r--server/lib/avatar.ts13
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',
56 // Check the rights 56 // Check the rights
57 asyncMiddleware(videoChannelsUpdateValidator), 57 asyncMiddleware(videoChannelsUpdateValidator),
58 updateAvatarValidator, 58 updateAvatarValidator,
59 asyncRetryTransactionMiddleware(updateVideoChannelAvatar) 59 asyncMiddleware(updateVideoChannelAvatar)
60) 60)
61 61
62videoChannelRouter.put('/:nameWithHost', 62videoChannelRouter.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'
6import { AccountModel } from '../models/account/account' 6import { AccountModel } from '../models/account/account'
7import { VideoChannelModel } from '../models/video/video-channel' 7import { VideoChannelModel } from '../models/video/video-channel'
8import { extname, join } from 'path' 8import { extname, join } from 'path'
9import { retryTransactionWrapper } from '../helpers/database-utils'
9 10
10async function updateActorAvatarFile (avatarPhysicalFile: Express.Multer.File, accountOrChannel: AccountModel | VideoChannelModel) { 11async function updateActorAvatarFile (avatarPhysicalFile: Express.Multer.File, accountOrChannel: AccountModel | VideoChannelModel) {
11 const extension = extname(avatarPhysicalFile.filename) 12 const extension = extname(avatarPhysicalFile.filename)
@@ -13,13 +14,15 @@ async function updateActorAvatarFile (avatarPhysicalFile: Express.Multer.File, a
13 const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName) 14 const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName)
14 await processImage(avatarPhysicalFile, destination, AVATARS_SIZE) 15 await processImage(avatarPhysicalFile, destination, AVATARS_SIZE)
15 16
16 return sequelizeTypescript.transaction(async t => { 17 return retryTransactionWrapper(() => {
17 const updatedActor = await updateActorAvatarInstance(accountOrChannel.Actor, avatarName, t) 18 return sequelizeTypescript.transaction(async t => {
18 await updatedActor.save({ transaction: t }) 19 const updatedActor = await updateActorAvatarInstance(accountOrChannel.Actor, avatarName, t)
20 await updatedActor.save({ transaction: t })
19 21
20 await sendUpdateActor(accountOrChannel, t) 22 await sendUpdateActor(accountOrChannel, t)
21 23
22 return updatedActor.Avatar 24 return updatedActor.Avatar
25 })
23 }) 26 })
24} 27}
25 28