aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/actors
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-08 17:29:45 +0200
committerChocobozzz <me@florianbigard.com>2021-06-08 17:41:48 +0200
commit28dfb44b145c537aba07ae73cb1287f25532022a (patch)
tree4aee64a049b396c8689f29e5ca8a8094dd3baf54 /server/lib/activitypub/actors
parent75e12406e271e3aaf1f7c394a63ce570091db480 (diff)
downloadPeerTube-28dfb44b145c537aba07ae73cb1287f25532022a.tar.gz
PeerTube-28dfb44b145c537aba07ae73cb1287f25532022a.tar.zst
PeerTube-28dfb44b145c537aba07ae73cb1287f25532022a.zip
Try to speed up AP update transaction
Diffstat (limited to 'server/lib/activitypub/actors')
-rw-r--r--server/lib/activitypub/actors/get.ts2
-rw-r--r--server/lib/activitypub/actors/updater.ts24
2 files changed, 13 insertions, 13 deletions
diff --git a/server/lib/activitypub/actors/get.ts b/server/lib/activitypub/actors/get.ts
index c7b49d6e4..de93aa964 100644
--- a/server/lib/activitypub/actors/get.ts
+++ b/server/lib/activitypub/actors/get.ts
@@ -56,7 +56,7 @@ async function getOrCreateAPActor (
56 if (actor.Account) (actor as MActorAccountChannelIdActor).Account.Actor = actor 56 if (actor.Account) (actor as MActorAccountChannelIdActor).Account.Actor = actor
57 if (actor.VideoChannel) (actor as MActorAccountChannelIdActor).VideoChannel.Actor = actor 57 if (actor.VideoChannel) (actor as MActorAccountChannelIdActor).VideoChannel.Actor = actor
58 58
59 const { actor: actorRefreshed, refreshed } = await retryTransactionWrapper(refreshActorIfNeeded, actor, fetchType) 59 const { actor: actorRefreshed, refreshed } = await refreshActorIfNeeded(actor, fetchType)
60 if (!actorRefreshed) throw new Error('Actor ' + actor.url + ' does not exist anymore.') 60 if (!actorRefreshed) throw new Error('Actor ' + actor.url + ' does not exist anymore.')
61 61
62 await scheduleOutboxFetchIfNeeded(actor, created, refreshed, updateCollections) 62 await scheduleOutboxFetchIfNeeded(actor, created, refreshed, updateCollections)
diff --git a/server/lib/activitypub/actors/updater.ts b/server/lib/activitypub/actors/updater.ts
index 471688f11..fb880a767 100644
--- a/server/lib/activitypub/actors/updater.ts
+++ b/server/lib/activitypub/actors/updater.ts
@@ -1,6 +1,5 @@
1import { resetSequelizeInstance } from '@server/helpers/database-utils' 1import { resetSequelizeInstance, runInReadCommittedTransaction } from '@server/helpers/database-utils'
2import { logger } from '@server/helpers/logger' 2import { logger } from '@server/helpers/logger'
3import { sequelizeTypescript } from '@server/initializers/database'
4import { VideoChannelModel } from '@server/models/video/video-channel' 3import { VideoChannelModel } from '@server/models/video/video-channel'
5import { MAccount, MActor, MActorFull, MChannel } from '@server/types/models' 4import { MAccount, MActor, MActorFull, MChannel } from '@server/types/models'
6import { ActivityPubActor, ActorImageType } from '@shared/models' 5import { ActivityPubActor, ActorImageType } from '@shared/models'
@@ -32,22 +31,23 @@ export class APActorUpdater {
32 const bannerInfo = getImageInfoFromObject(this.actorObject, ActorImageType.BANNER) 31 const bannerInfo = getImageInfoFromObject(this.actorObject, ActorImageType.BANNER)
33 32
34 try { 33 try {
35 await sequelizeTypescript.transaction(async t => { 34 await this.updateActorInstance(this.actor, this.actorObject)
36 await this.updateActorInstance(this.actor, this.actorObject)
37 35
38 await updateActorImageInstance(this.actor, ActorImageType.AVATAR, avatarInfo, t) 36 this.accountOrChannel.name = this.actorObject.name || this.actorObject.preferredUsername
39 await updateActorImageInstance(this.actor, ActorImageType.BANNER, bannerInfo, t) 37 this.accountOrChannel.description = this.actorObject.summary
40
41 await this.actor.save({ transaction: t })
42
43 this.accountOrChannel.name = this.actorObject.name || this.actorObject.preferredUsername
44 this.accountOrChannel.description = this.actorObject.summary
45 38
46 if (this.accountOrChannel instanceof VideoChannelModel) this.accountOrChannel.support = this.actorObject.support 39 if (this.accountOrChannel instanceof VideoChannelModel) this.accountOrChannel.support = this.actorObject.support
47 40
41 await runInReadCommittedTransaction(async t => {
42 await this.actor.save({ transaction: t })
48 await this.accountOrChannel.save({ transaction: t }) 43 await this.accountOrChannel.save({ transaction: t })
49 }) 44 })
50 45
46 await runInReadCommittedTransaction(async t => {
47 await updateActorImageInstance(this.actor, ActorImageType.AVATAR, avatarInfo, t)
48 await updateActorImageInstance(this.actor, ActorImageType.BANNER, bannerInfo, t)
49 })
50
51 logger.info('Remote account %s updated', this.actorObject.url) 51 logger.info('Remote account %s updated', this.actorObject.url)
52 } catch (err) { 52 } catch (err) {
53 if (this.actor !== undefined && this.actorFieldsSave !== undefined) { 53 if (this.actor !== undefined && this.actorFieldsSave !== undefined) {