perf: Requesting less db columns when calculating collection permissions (#3498)
perf: Not looping collection documentStructure for unpublish permission calculation
This commit is contained in:
@@ -98,11 +98,12 @@ export const DOCUMENT_VERSION = 2;
|
||||
},
|
||||
}))
|
||||
@Scopes(() => ({
|
||||
withCollection: (userId: string, paranoid = true) => {
|
||||
withCollectionPermissions: (userId: string, paranoid = true) => {
|
||||
if (userId) {
|
||||
return {
|
||||
include: [
|
||||
{
|
||||
attributes: ["id", "permission", "sharing", "teamId", "deletedAt"],
|
||||
model: Collection.scope({
|
||||
method: ["withMembership", userId],
|
||||
}),
|
||||
@@ -116,8 +117,10 @@ export const DOCUMENT_VERSION = 2;
|
||||
return {
|
||||
include: [
|
||||
{
|
||||
attributes: ["id", "permission", "sharing", "teamId", "deletedAt"],
|
||||
model: Collection,
|
||||
as: "collection",
|
||||
paranoid,
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -127,6 +130,14 @@ export const DOCUMENT_VERSION = 2;
|
||||
exclude: ["state"],
|
||||
},
|
||||
},
|
||||
withCollection: {
|
||||
include: [
|
||||
{
|
||||
model: Collection,
|
||||
as: "collection",
|
||||
},
|
||||
],
|
||||
},
|
||||
withState: {
|
||||
attributes: {
|
||||
// resets to include the state column
|
||||
@@ -390,7 +401,7 @@ class Document extends ParanoidModel {
|
||||
|
||||
static defaultScopeWithUser(userId: string) {
|
||||
const collectionScope: Readonly<ScopeOptions> = {
|
||||
method: ["withCollection", userId],
|
||||
method: ["withCollectionPermissions", userId],
|
||||
};
|
||||
const viewScope: Readonly<ScopeOptions> = {
|
||||
method: ["withViews", userId],
|
||||
@@ -410,7 +421,7 @@ class Document extends ParanoidModel {
|
||||
"withoutState",
|
||||
"withDrafts",
|
||||
{
|
||||
method: ["withCollection", options.userId, options.paranoid],
|
||||
method: ["withCollectionPermissions", options.userId, options.paranoid],
|
||||
},
|
||||
{
|
||||
method: ["withViews", options.userId],
|
||||
@@ -670,7 +681,7 @@ class Document extends ParanoidModel {
|
||||
method: ["withViews", user.id],
|
||||
},
|
||||
{
|
||||
method: ["withCollection", user.id],
|
||||
method: ["withCollectionPermissions", user.id],
|
||||
},
|
||||
]).findAll({
|
||||
where: {
|
||||
|
||||
@@ -30,7 +30,7 @@ import Fix from "./decorators/Fix";
|
||||
],
|
||||
}))
|
||||
@Scopes(() => ({
|
||||
withCollection: (userId: string) => {
|
||||
withCollectionPermissions: (userId: string) => {
|
||||
return {
|
||||
include: [
|
||||
{
|
||||
@@ -39,6 +39,13 @@ import Fix from "./decorators/Fix";
|
||||
as: "document",
|
||||
include: [
|
||||
{
|
||||
attributes: [
|
||||
"id",
|
||||
"permission",
|
||||
"sharing",
|
||||
"teamId",
|
||||
"deletedAt",
|
||||
],
|
||||
model: Collection.scope({
|
||||
method: ["withMembership", userId],
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user