perf: Remove collaborators from documents.list response (#2039)
* fix: Remove unused, unperformant query * lint * collaborators -> collaboratorIds
This commit is contained in:
@ -24,7 +24,7 @@ export default class Document extends BaseModel {
|
|||||||
@observable lastViewedAt: ?string;
|
@observable lastViewedAt: ?string;
|
||||||
store: DocumentsStore;
|
store: DocumentsStore;
|
||||||
|
|
||||||
collaborators: User[];
|
collaboratorIds: string[];
|
||||||
collectionId: string;
|
collectionId: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
createdBy: User;
|
createdBy: User;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import { takeRight } from "lodash";
|
import { Attachment, Document } from "../models";
|
||||||
import { Attachment, Document, User } from "../models";
|
|
||||||
import parseAttachmentIds from "../utils/parseAttachmentIds";
|
import parseAttachmentIds from "../utils/parseAttachmentIds";
|
||||||
import { getSignedImageUrl } from "../utils/s3";
|
import { getSignedImageUrl } from "../utils/s3";
|
||||||
import presentUser from "./user";
|
import presentUser from "./user";
|
||||||
@ -53,7 +52,7 @@ export default async function present(document: Document, options: ?Options) {
|
|||||||
teamId: document.teamId,
|
teamId: document.teamId,
|
||||||
template: document.template,
|
template: document.template,
|
||||||
templateId: document.templateId,
|
templateId: document.templateId,
|
||||||
collaborators: [],
|
collaboratorIds: [],
|
||||||
starred: document.starred ? !!document.starred.length : undefined,
|
starred: document.starred ? !!document.starred.length : undefined,
|
||||||
revision: document.revisionCount,
|
revision: document.revisionCount,
|
||||||
pinned: undefined,
|
pinned: undefined,
|
||||||
@ -72,15 +71,7 @@ export default async function present(document: Document, options: ?Options) {
|
|||||||
data.parentDocumentId = document.parentDocumentId;
|
data.parentDocumentId = document.parentDocumentId;
|
||||||
data.createdBy = presentUser(document.createdBy);
|
data.createdBy = presentUser(document.createdBy);
|
||||||
data.updatedBy = presentUser(document.updatedBy);
|
data.updatedBy = presentUser(document.updatedBy);
|
||||||
|
data.collaboratorIds = document.collaboratorIds;
|
||||||
// TODO: This could be further optimized
|
|
||||||
data.collaborators = (
|
|
||||||
await User.findAll({
|
|
||||||
where: {
|
|
||||||
id: takeRight(document.collaboratorIds, 10) || [],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
).map(presentUser);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
Reference in New Issue
Block a user