perf: Remove withStarred scope and starred property on documents

closes #3081
This commit is contained in:
Tom Moor
2022-02-09 19:51:51 -08:00
parent 5bc4405b23
commit b3f33c1101
2 changed files with 1 additions and 23 deletions

View File

@@ -144,19 +144,6 @@ export const DOCUMENT_VERSION = 2;
], ],
}; };
}, },
withStarred: (userId: string) => ({
include: [
{
model: Star,
as: "starred",
where: {
userId,
},
required: false,
separate: true,
},
],
}),
})) }))
@Table({ tableName: "documents", modelName: "document" }) @Table({ tableName: "documents", modelName: "document" })
@Fix @Fix
@@ -365,21 +352,13 @@ class Document extends ParanoidModel {
views: View[]; views: View[];
static defaultScopeWithUser(userId: string) { static defaultScopeWithUser(userId: string) {
const starredScope: Readonly<ScopeOptions> = {
method: ["withStarred", userId],
};
const collectionScope: Readonly<ScopeOptions> = { const collectionScope: Readonly<ScopeOptions> = {
method: ["withCollection", userId], method: ["withCollection", userId],
}; };
const viewScope: Readonly<ScopeOptions> = { const viewScope: Readonly<ScopeOptions> = {
method: ["withViews", userId], method: ["withViews", userId],
}; };
return this.scope([ return this.scope(["defaultScope", collectionScope, viewScope]);
"defaultScope",
starredScope,
collectionScope,
viewScope,
]);
} }
static async findByPk( static async findByPk(

View File

@@ -56,7 +56,6 @@ export default async function present(
template: document.template, template: document.template,
templateId: document.templateId, templateId: document.templateId,
collaboratorIds: [], collaboratorIds: [],
starred: document.starred ? !!document.starred.length : undefined,
revision: document.revisionCount, revision: document.revisionCount,
fullWidth: document.fullWidth, fullWidth: document.fullWidth,
collectionId: undefined, collectionId: undefined,