perf: Requesting less db columns when calculating collection permissions (#3498)
perf: Not looping collection documentStructure for unpublish permission calculation
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user