refactor: Trim down the response on the Workflows listing endpoint (#4726)

* fix: Avoid hashing workflows in the listing page

* stop returning full nodes data on the listings page when sharing is enabled

* fix the relations array for workflow listing

* add a comment explaining the hash skipping hack
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2022-11-25 14:20:28 +01:00 committed by GitHub
parent 39a5dc57a8
commit 1579d05fd1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 32 deletions

View file

@ -101,6 +101,9 @@ export class WorkflowEntity extends AbstractEntity implements IWorkflowDb {
setHash(): void { setHash(): void {
const { name, active, nodes, connections, settings, staticData, pinData } = this; const { name, active, nodes, connections, settings, staticData, pinData } = this;
// Workflow listing page does not request the `connections` column, so we can use this for `undefined` to avoid generating hashes for all the workflows.
if (!connections) return;
const state = JSON.stringify({ const state = JSON.stringify({
name, name,
active, active,

View file

@ -97,10 +97,9 @@ EEWorkflowController.get(
); );
} }
return EEWorkflows.addCredentialsToWorkflow( EEWorkflows.addOwnerAndSharings(workflow);
EEWorkflows.addOwnerAndSharings(workflow), await EEWorkflows.addCredentialsToWorkflow(workflow, req.user);
req.user, return workflow;
);
}), }),
); );
@ -200,9 +199,12 @@ EEWorkflowController.get(
)) as unknown as WorkflowEntity[]; )) as unknown as WorkflowEntity[];
return Promise.all( return Promise.all(
workflows.map(async (workflow) => workflows.map(async (workflow) => {
EEWorkflows.addCredentialsToWorkflow(EEWorkflows.addOwnerAndSharings(workflow), req.user), EEWorkflows.addOwnerAndSharings(workflow);
), await EEWorkflows.addCredentialsToWorkflow(workflow, req.user);
workflow.nodes = [];
return workflow;
}),
); );
}), }),
); );

View file

@ -85,9 +85,7 @@ export class EEWorkflowsService extends WorkflowsService {
return transaction.save(newSharedWorkflows); return transaction.save(newSharedWorkflows);
} }
static addOwnerAndSharings( static addOwnerAndSharings(workflow: WorkflowWithSharingsAndCredentials): void {
workflow: WorkflowWithSharingsAndCredentials,
): WorkflowWithSharingsAndCredentials {
workflow.ownedBy = null; workflow.ownedBy = null;
workflow.sharedWith = []; workflow.sharedWith = [];
workflow.usedCredentials = []; workflow.usedCredentials = [];
@ -104,14 +102,12 @@ export class EEWorkflowsService extends WorkflowsService {
}); });
delete workflow.shared; delete workflow.shared;
return workflow;
} }
static async addCredentialsToWorkflow( static async addCredentialsToWorkflow(
workflow: WorkflowWithSharingsAndCredentials, workflow: WorkflowWithSharingsAndCredentials,
currentUser: User, currentUser: User,
): Promise<WorkflowWithSharingsAndCredentials> { ): Promise<void> {
workflow.usedCredentials = []; workflow.usedCredentials = [];
const userCredentials = await EECredentials.getAll(currentUser); const userCredentials = await EECredentials.getAll(currentUser);
const credentialIdsUsedByWorkflow = new Set<number>(); const credentialIdsUsedByWorkflow = new Set<number>();
@ -155,8 +151,6 @@ export class EEWorkflowsService extends WorkflowsService {
}); });
workflow.usedCredentials?.push(workflowCredential); workflow.usedCredentials?.push(workflowCredential);
}); });
return workflow;
} }
static validateCredentialPermissionsToUser( static validateCredentialPermissionsToUser(

View file

@ -140,26 +140,27 @@ export class WorkflowsService {
} }
const fields: Array<keyof WorkflowEntity> = ['id', 'name', 'active', 'createdAt', 'updatedAt']; const fields: Array<keyof WorkflowEntity> = ['id', 'name', 'active', 'createdAt', 'updatedAt'];
const relations: string[] = [];
const query: FindManyOptions<WorkflowEntity> = { if (!config.getEnv('workflowTagsDisabled')) {
select: config.get('enterprise.features.sharing') ? [...fields, 'nodes'] : fields, relations.push('tags');
relations: config.get('enterprise.features.sharing')
? ['tags', 'shared', 'shared.user', 'shared.role']
: ['tags'],
};
if (config.getEnv('workflowTagsDisabled')) {
delete query.relations;
} }
const workflows = await Db.collections.Workflow.find( const isSharingEnabled = config.getEnv('enterprise.features.sharing');
Object.assign(query, { if (isSharingEnabled) {
where: { relations.push('shared', 'shared.user', 'shared.role');
id: In(sharedWorkflowIds), }
...filter,
}, const query: FindManyOptions<WorkflowEntity> = {
}), select: isSharingEnabled ? [...fields, 'nodes'] : fields,
); relations,
where: {
id: In(sharedWorkflowIds),
...filter,
},
};
const workflows = await Db.collections.Workflow.find(query);
return workflows.map((workflow) => { return workflows.map((workflow) => {
const { id, ...rest } = workflow; const { id, ...rest } = workflow;