diff --git a/packages/cli/src/databases/entities/WorkflowEntity.ts b/packages/cli/src/databases/entities/WorkflowEntity.ts index 4bb7168b82..06d47e40d1 100644 --- a/packages/cli/src/databases/entities/WorkflowEntity.ts +++ b/packages/cli/src/databases/entities/WorkflowEntity.ts @@ -101,6 +101,9 @@ export class WorkflowEntity extends AbstractEntity implements IWorkflowDb { setHash(): void { 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({ name, active, diff --git a/packages/cli/src/workflows/workflows.controller.ee.ts b/packages/cli/src/workflows/workflows.controller.ee.ts index 292e1092ec..5403c81445 100644 --- a/packages/cli/src/workflows/workflows.controller.ee.ts +++ b/packages/cli/src/workflows/workflows.controller.ee.ts @@ -97,10 +97,9 @@ EEWorkflowController.get( ); } - return EEWorkflows.addCredentialsToWorkflow( - EEWorkflows.addOwnerAndSharings(workflow), - req.user, - ); + EEWorkflows.addOwnerAndSharings(workflow); + await EEWorkflows.addCredentialsToWorkflow(workflow, req.user); + return workflow; }), ); @@ -200,9 +199,12 @@ EEWorkflowController.get( )) as unknown as WorkflowEntity[]; return Promise.all( - workflows.map(async (workflow) => - EEWorkflows.addCredentialsToWorkflow(EEWorkflows.addOwnerAndSharings(workflow), req.user), - ), + workflows.map(async (workflow) => { + EEWorkflows.addOwnerAndSharings(workflow); + await EEWorkflows.addCredentialsToWorkflow(workflow, req.user); + workflow.nodes = []; + return workflow; + }), ); }), ); diff --git a/packages/cli/src/workflows/workflows.services.ee.ts b/packages/cli/src/workflows/workflows.services.ee.ts index 21ce1cfbd1..fdc68db4da 100644 --- a/packages/cli/src/workflows/workflows.services.ee.ts +++ b/packages/cli/src/workflows/workflows.services.ee.ts @@ -85,9 +85,7 @@ export class EEWorkflowsService extends WorkflowsService { return transaction.save(newSharedWorkflows); } - static addOwnerAndSharings( - workflow: WorkflowWithSharingsAndCredentials, - ): WorkflowWithSharingsAndCredentials { + static addOwnerAndSharings(workflow: WorkflowWithSharingsAndCredentials): void { workflow.ownedBy = null; workflow.sharedWith = []; workflow.usedCredentials = []; @@ -104,14 +102,12 @@ export class EEWorkflowsService extends WorkflowsService { }); delete workflow.shared; - - return workflow; } static async addCredentialsToWorkflow( workflow: WorkflowWithSharingsAndCredentials, currentUser: User, - ): Promise { + ): Promise { workflow.usedCredentials = []; const userCredentials = await EECredentials.getAll(currentUser); const credentialIdsUsedByWorkflow = new Set(); @@ -155,8 +151,6 @@ export class EEWorkflowsService extends WorkflowsService { }); workflow.usedCredentials?.push(workflowCredential); }); - - return workflow; } static validateCredentialPermissionsToUser( diff --git a/packages/cli/src/workflows/workflows.services.ts b/packages/cli/src/workflows/workflows.services.ts index 9b4df6e17d..27dfc2ed62 100644 --- a/packages/cli/src/workflows/workflows.services.ts +++ b/packages/cli/src/workflows/workflows.services.ts @@ -140,26 +140,27 @@ export class WorkflowsService { } const fields: Array = ['id', 'name', 'active', 'createdAt', 'updatedAt']; + const relations: string[] = []; - const query: FindManyOptions = { - select: config.get('enterprise.features.sharing') ? [...fields, 'nodes'] : fields, - relations: config.get('enterprise.features.sharing') - ? ['tags', 'shared', 'shared.user', 'shared.role'] - : ['tags'], - }; - - if (config.getEnv('workflowTagsDisabled')) { - delete query.relations; + if (!config.getEnv('workflowTagsDisabled')) { + relations.push('tags'); } - const workflows = await Db.collections.Workflow.find( - Object.assign(query, { - where: { - id: In(sharedWorkflowIds), - ...filter, - }, - }), - ); + const isSharingEnabled = config.getEnv('enterprise.features.sharing'); + if (isSharingEnabled) { + relations.push('shared', 'shared.user', 'shared.role'); + } + + const query: FindManyOptions = { + select: isSharingEnabled ? [...fields, 'nodes'] : fields, + relations, + where: { + id: In(sharedWorkflowIds), + ...filter, + }, + }; + + const workflows = await Db.collections.Workflow.find(query); return workflows.map((workflow) => { const { id, ...rest } = workflow;