From 940ad8479e463f9603d85a0ddd3998b0066042f6 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 15 Apr 2021 22:49:16 -0700 Subject: [PATCH] perf: Remove collaborators from documents.list response (#2039) * fix: Remove unused, unperformant query * lint * collaborators -> collaboratorIds --- app/models/Document.js | 2 +- server/presenters/document.js | 15 +++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/app/models/Document.js b/app/models/Document.js index bebb34c86..c6061ff2a 100644 --- a/app/models/Document.js +++ b/app/models/Document.js @@ -24,7 +24,7 @@ export default class Document extends BaseModel { @observable lastViewedAt: ?string; store: DocumentsStore; - collaborators: User[]; + collaboratorIds: string[]; collectionId: string; createdAt: string; createdBy: User; diff --git a/server/presenters/document.js b/server/presenters/document.js index fe48c06e4..edfc4fa8d 100644 --- a/server/presenters/document.js +++ b/server/presenters/document.js @@ -1,6 +1,5 @@ // @flow -import { takeRight } from "lodash"; -import { Attachment, Document, User } from "../models"; +import { Attachment, Document } from "../models"; import parseAttachmentIds from "../utils/parseAttachmentIds"; import { getSignedImageUrl } from "../utils/s3"; import presentUser from "./user"; @@ -53,7 +52,7 @@ export default async function present(document: Document, options: ?Options) { teamId: document.teamId, template: document.template, templateId: document.templateId, - collaborators: [], + collaboratorIds: [], starred: document.starred ? !!document.starred.length : undefined, revision: document.revisionCount, pinned: undefined, @@ -72,15 +71,7 @@ export default async function present(document: Document, options: ?Options) { data.parentDocumentId = document.parentDocumentId; data.createdBy = presentUser(document.createdBy); data.updatedBy = presentUser(document.updatedBy); - - // TODO: This could be further optimized - data.collaborators = ( - await User.findAll({ - where: { - id: takeRight(document.collaboratorIds, 10) || [], - }, - }) - ).map(presentUser); + data.collaboratorIds = document.collaboratorIds; } return data;