From c9bf57e5d5220376a5453218fc281120637690e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Tue, 12 Dec 2023 11:14:04 +0100 Subject: [PATCH] refactor(core): Don't use DB transactions on ExecutionRepository.createNewExecution (no-changelog) --- packages/cli/src/ActiveExecutions.ts | 4 +- .../repositories/execution.repository.ts | 37 +++++++++++++------ .../cli/test/unit/ActiveExecutions.test.ts | 4 +- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/packages/cli/src/ActiveExecutions.ts b/packages/cli/src/ActiveExecutions.ts index ceb74d628ca27f..cd8ce8ecdbe706 100644 --- a/packages/cli/src/ActiveExecutions.ts +++ b/packages/cli/src/ActiveExecutions.ts @@ -60,9 +60,7 @@ export class ActiveExecutions { fullExecutionData.workflowId = workflowId; } - const executionResult = - await Container.get(ExecutionRepository).createNewExecution(fullExecutionData); - executionId = executionResult.id; + executionId = await Container.get(ExecutionRepository).createNewExecution(fullExecutionData); if (executionId === undefined) { throw new ApplicationError('There was an issue assigning an execution id to the execution'); } diff --git a/packages/cli/src/databases/repositories/execution.repository.ts b/packages/cli/src/databases/repositories/execution.repository.ts index f8e1350588fa95..1ee28e3147e028 100644 --- a/packages/cli/src/databases/repositories/execution.repository.ts +++ b/packages/cli/src/databases/repositories/execution.repository.ts @@ -25,7 +25,7 @@ import type { import config from '@/config'; import type { IGetExecutionsQueryFilter } from '@/executions/executions.service'; import { isAdvancedExecutionFiltersEnabled } from '@/executions/executionHelpers'; -import type { ExecutionData } from '../entities/ExecutionData'; +import { ExecutionData } from '../entities/ExecutionData'; import { ExecutionEntity } from '../entities/ExecutionEntity'; import { ExecutionMetadata } from '../entities/ExecutionMetadata'; import { ExecutionDataRepository } from './executionData.repository'; @@ -213,17 +213,32 @@ export class ExecutionRepository extends Repository { return rest; } - async createNewExecution(execution: ExecutionPayload) { + async createNewExecution(execution: ExecutionPayload): Promise { const { data, workflowData, ...rest } = execution; - - const newExecution = await this.save(rest); - await this.executionDataRepository.save({ - execution: newExecution, - workflowData, - data: stringify(data), - }); - - return newExecution; + const { identifiers: inserted } = await this.manager + .createQueryBuilder() + .insert() + .into(ExecutionEntity) + .values([rest]) + .returning('id') + .execute(); + + const { id: executionId } = inserted[0] as { id: string }; + const { connections, nodes, name, pinData, staticData } = workflowData ?? {}; + await this.manager + .createQueryBuilder() + .insert() + .into(ExecutionData) + .values([ + { + executionId, + // @ts-ignore + workflowData: { connections, nodes, name, pinData: pinData!, staticData }, + data: stringify(data), + }, + ]) + .execute(); + return executionId; } async markAsCrashed(executionIds: string[]) { diff --git a/packages/cli/test/unit/ActiveExecutions.test.ts b/packages/cli/test/unit/ActiveExecutions.test.ts index 689bbbefabf4ba..6ac1438b4bb0d8 100644 --- a/packages/cli/test/unit/ActiveExecutions.test.ts +++ b/packages/cli/test/unit/ActiveExecutions.test.ts @@ -12,9 +12,7 @@ const FAKE_EXECUTION_ID = '15'; const FAKE_SECOND_EXECUTION_ID = '20'; const updateExistingExecution = jest.fn(); -const createNewExecution = jest.fn(async () => { - return { id: FAKE_EXECUTION_ID }; -}); +const createNewExecution = jest.fn(async () => FAKE_EXECUTION_ID); Container.set(ExecutionRepository, { updateExistingExecution,