From 21adfdd1bf2ff74657cfb4fe63d13f99ff3ca52b Mon Sep 17 00:00:00 2001 From: Hemachandar <132386067+hmacr@users.noreply.github.com> Date: Sun, 29 Sep 2024 22:13:07 +0530 Subject: [PATCH] perf: use findAll for querying document collaborators (#7697) * perf: use findAll for querying document collaborators * remove unnecessary compact --- server/models/Document.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/server/models/Document.ts b/server/models/Document.ts index af44aa21ce..7ca891878b 100644 --- a/server/models/Document.ts +++ b/server/models/Document.ts @@ -807,15 +807,14 @@ class Document extends ParanoidModel< * @param options FindOptions * @returns A promise that resolve to a list of users */ - collaborators = async (options?: FindOptions): Promise => { - const users = await Promise.all( - this.collaboratorIds.map((collaboratorId) => - User.findByPk(collaboratorId, options) - ) - ); - - return compact(users); - }; + collaborators = async (options?: FindOptions): Promise => + await User.findAll({ + ...options, + where: { + ...options?.where, + id: this.collaboratorIds, + }, + }); /** * Find all of the child documents for this document