From cc39c50737b7ff2b04ca5e93a1c1bde6a42464bc Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Tue, 8 Jul 2025 14:40:55 -0400 Subject: [PATCH] perf(core): Improvements to GET `/workflows` endpoint (#17086) --- .../db/src/repositories/tag.repository.ts | 6 ++++++ .../handlers/workflows/workflows.handler.ts | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/packages/@n8n/db/src/repositories/tag.repository.ts b/packages/@n8n/db/src/repositories/tag.repository.ts index d27843690f..ad2e1f8f2a 100644 --- a/packages/@n8n/db/src/repositories/tag.repository.ts +++ b/packages/@n8n/db/src/repositories/tag.repository.ts @@ -65,6 +65,12 @@ export class TagRepository extends Repository { const dbTags = await this.find({ where: { name: In(tags) }, relations: ['workflows'], + select: { + id: true, + workflows: { + id: true, + }, + }, }); const workflowIdsPerTag = dbTags.map((tag) => tag.workflows.map((workflow) => workflow.id)); diff --git a/packages/cli/src/public-api/v1/handlers/workflows/workflows.handler.ts b/packages/cli/src/public-api/v1/handlers/workflows/workflows.handler.ts index 1763c5ad0f..2e1adba699 100644 --- a/packages/cli/src/public-api/v1/handlers/workflows/workflows.handler.ts +++ b/packages/cli/src/public-api/v1/handlers/workflows/workflows.handler.ts @@ -211,9 +211,30 @@ export = { where.id = In(workflowsIds); } + const selectFields: (keyof WorkflowEntity)[] = [ + 'id', + 'name', + 'active', + 'createdAt', + 'updatedAt', + 'isArchived', + 'nodes', + 'connections', + 'settings', + 'staticData', + 'meta', + 'versionId', + 'triggerCount', + ]; + + if (!excludePinnedData) { + selectFields.push('pinData'); + } + const [workflows, count] = await Container.get(WorkflowRepository).findAndCount({ skip: offset, take: limit, + select: selectFields, where, ...(!Container.get(GlobalConfig).tags.disabled && { relations: ['tags'] }), });