From 2ef827ee6f2270d4b01e76038352b6c9bf93fe48 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 10 Mar 2022 18:13:18 -0800 Subject: [PATCH] perf: Add teamId to search query to help with query planning --- server/models/Document.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/server/models/Document.ts b/server/models/Document.ts index 28b877fcd..64548bda1 100644 --- a/server/models/Document.ts +++ b/server/models/Document.ts @@ -477,26 +477,18 @@ class Document extends ParanoidModel { resultsQuery, countQuery, ]); + // Final query to get associated document data const documents = await this.findAll({ where: { id: map(results, "id"), + teamId: team.id, }, include: [ { model: Collection, as: "collection", }, - { - model: User, - as: "createdBy", - paranoid: false, - }, - { - model: User, - as: "updatedBy", - paranoid: false, - }, ], }); @@ -620,9 +612,11 @@ class Document extends ParanoidModel { }, ]).findAll({ where: { + teamId: user.teamId, id: map(results, "id"), }, }); + return { results: map(results, (result: any) => ({ ranking: result.searchRanking,