From e587e0ecee5bec43a225995948faaa4bc97f080a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 19 Sep 2018 14:44:20 +0200 Subject: Optimize activity actor load in AP processors --- server/lib/activitypub/process/process-update.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'server/lib/activitypub/process/process-update.ts') diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts index 0bceb370e..ed3489ebf 100644 --- a/server/lib/activitypub/process/process-update.ts +++ b/server/lib/activitypub/process/process-update.ts @@ -6,27 +6,30 @@ import { sequelizeTypescript } from '../../../initializers' import { AccountModel } from '../../../models/account/account' import { ActorModel } from '../../../models/activitypub/actor' import { VideoChannelModel } from '../../../models/video/video-channel' -import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor' -import { getOrCreateVideoAndAccountAndChannel, updateVideoFromAP, getOrCreateVideoChannelFromVideoObject } from '../videos' +import { fetchAvatarIfExists, updateActorAvatarInstance, updateActorInstance } from '../actor' +import { getOrCreateVideoAndAccountAndChannel, getOrCreateVideoChannelFromVideoObject, updateVideoFromAP } from '../videos' import { sanitizeAndCheckVideoTorrentObject } from '../../../helpers/custom-validators/activitypub/videos' import { isCacheFileObjectValid } from '../../../helpers/custom-validators/activitypub/cache-file' import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy' import { createCacheFile, updateCacheFile } from '../cache-file' -async function processUpdateActivity (activity: ActivityUpdate) { - const actor = await getOrCreateActorAndServerAndModel(activity.actor) +async function processUpdateActivity (activity: ActivityUpdate, byActor: ActorModel) { const objectType = activity.object.type if (objectType === 'Video') { - return retryTransactionWrapper(processUpdateVideo, actor, activity) + return retryTransactionWrapper(processUpdateVideo, byActor, activity) } if (objectType === 'Person' || objectType === 'Application' || objectType === 'Group') { - return retryTransactionWrapper(processUpdateActor, actor, activity) + // We need more attributes + const byActorFull = await ActorModel.loadByUrlAndPopulateAccountAndChannel(byActor.url) + return retryTransactionWrapper(processUpdateActor, byActorFull, activity) } if (objectType === 'CacheFile') { - return retryTransactionWrapper(processUpdateCacheFile, actor, activity) + // We need more attributes + const byActorFull = await ActorModel.loadByUrlAndPopulateAccountAndChannel(byActor.url) + return retryTransactionWrapper(processUpdateCacheFile, byActorFull, activity) } return undefined -- cgit v1.2.3