]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/actors/updater.ts
Try to speed up AP update transaction
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / actors / updater.ts
index 471688f11feec66a825567c78b6a87286608cb18..fb880a76796b5e6e4424caaf60918f9e80fdccd7 100644 (file)
@@ -1,6 +1,5 @@
-import { resetSequelizeInstance } from '@server/helpers/database-utils'
+import { resetSequelizeInstance, runInReadCommittedTransaction } from '@server/helpers/database-utils'
 import { logger } from '@server/helpers/logger'
-import { sequelizeTypescript } from '@server/initializers/database'
 import { VideoChannelModel } from '@server/models/video/video-channel'
 import { MAccount, MActor, MActorFull, MChannel } from '@server/types/models'
 import { ActivityPubActor, ActorImageType } from '@shared/models'
@@ -32,22 +31,23 @@ export class APActorUpdater {
     const bannerInfo = getImageInfoFromObject(this.actorObject, ActorImageType.BANNER)
 
     try {
-      await sequelizeTypescript.transaction(async t => {
-        await this.updateActorInstance(this.actor, this.actorObject)
+      await this.updateActorInstance(this.actor, this.actorObject)
 
-        await updateActorImageInstance(this.actor, ActorImageType.AVATAR, avatarInfo, t)
-        await updateActorImageInstance(this.actor, ActorImageType.BANNER, bannerInfo, t)
-
-        await this.actor.save({ transaction: t })
-
-        this.accountOrChannel.name = this.actorObject.name || this.actorObject.preferredUsername
-        this.accountOrChannel.description = this.actorObject.summary
+      this.accountOrChannel.name = this.actorObject.name || this.actorObject.preferredUsername
+      this.accountOrChannel.description = this.actorObject.summary
 
-        if (this.accountOrChannel instanceof VideoChannelModel) this.accountOrChannel.support = this.actorObject.support
+      if (this.accountOrChannel instanceof VideoChannelModel) this.accountOrChannel.support = this.actorObject.support
 
+      await runInReadCommittedTransaction(async t => {
+        await this.actor.save({ transaction: t })
         await this.accountOrChannel.save({ transaction: t })
       })
 
+      await runInReadCommittedTransaction(async t => {
+        await updateActorImageInstance(this.actor, ActorImageType.AVATAR, avatarInfo, t)
+        await updateActorImageInstance(this.actor, ActorImageType.BANNER, bannerInfo, t)
+      })
+
       logger.info('Remote account %s updated', this.actorObject.url)
     } catch (err) {
       if (this.actor !== undefined && this.actorFieldsSave !== undefined) {