perf: Remove collaborators from documents.list response (#2039)

* fix: Remove unused, unperformant query

* lint

* collaborators -> collaboratorIds
This commit is contained in:
Tom Moor
2021-04-15 22:49:16 -07:00
committed by GitHub
parent c5401a467d
commit 940ad8479e
2 changed files with 4 additions and 13 deletions

View File

@ -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;