From 2c897999fe877c52c8f7458d8bbff6c9367b6587 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 18 Jan 2018 15:22:36 +0100 Subject: Optimize SQL query that fetch actor outbox --- server/lib/activitypub/actor.ts | 42 +++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'server/lib') diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index a39b4e137..7494aadbb 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts @@ -212,7 +212,13 @@ function saveActorAndServerAndModelIfNotExist ( // Force the actor creation, sometimes Sequelize skips the save() when it thinks the instance already exists // (which could be false in a retried query) - const actorCreated = await ActorModel.create(actor.toJSON(), { transaction: t }) + const [ actorCreated ] = await ActorModel.findOrCreate({ + defaults: actor.toJSON(), + where: { + url: actor.url + }, + transaction: t + }) if (actorCreated.type === 'Person' || actorCreated.type === 'Application') { const account = await saveAccount(actorCreated, result, t) @@ -284,24 +290,36 @@ async function fetchRemoteActor (actorUrl: string): Promise