perf: Requesting less db columns when calculating collection permissions (#3498)

perf: Not looping collection documentStructure for unpublish permission calculation
This commit is contained in:
Tom Moor
2022-05-15 06:46:24 -07:00
committed by GitHub
parent 36a3ae4b01
commit 8815a58ff5
5 changed files with 43 additions and 30 deletions

View File

@@ -175,7 +175,7 @@ router.post("documents.archived", auth(), pagination(), async (ctx) => {
const { user } = ctx.state;
const collectionIds = await user.collectionIds();
const collectionScope: Readonly<ScopeOptions> = {
method: ["withCollection", user.id],
method: ["withCollectionPermissions", user.id],
};
const viewScope: Readonly<ScopeOptions> = {
method: ["withViews", user.id],
@@ -221,7 +221,7 @@ router.post("documents.deleted", auth(), pagination(), async (ctx) => {
paranoid: false,
});
const collectionScope: Readonly<ScopeOptions> = {
method: ["withCollection", user.id],
method: ["withCollectionPermissions", user.id],
};
const viewScope: Readonly<ScopeOptions> = {
method: ["withViews", user.id],
@@ -359,7 +359,7 @@ router.post("documents.drafts", auth(), pagination(), async (ctx) => {
}
const collectionScope: Readonly<ScopeOptions> = {
method: ["withCollection", user.id],
method: ["withCollectionPermissions", user.id],
};
const documents = await Document.scope([
"defaultScope",
@@ -710,7 +710,7 @@ router.post("documents.search_titles", auth(), pagination(), async (ctx) => {
method: ["withViews", user.id],
},
{
method: ["withCollection", user.id],
method: ["withCollectionPermissions", user.id],
},
]).findAll({
where: {
@@ -1219,6 +1219,11 @@ router.post("documents.unpublish", auth(), async (ctx) => {
});
authorize(user, "unpublish", document);
const childDocumentIds = await document.getChildDocumentIds();
if (childDocumentIds.length > 0) {
throw InvalidRequestError("Cannot unpublish document with child documents");
}
await document.unpublish(user.id);
await Event.create({
name: "documents.unpublish",