refactor(core): Don't use DB transactions on ExecutionRepository.createNewExecution (#8002)

Saving execution data is one of the slowest DB operations in the
application, and is likely behind some of the sqlite transaction
concurrency issues we've been seeing.
This not only remove the 2 separate transactions for saving
`ExecutionEntity` and `ExecutionData`, but also remove fields from
`ExecutionData.workflowData` that don't need to be saved (like `tags`,
`shared`, `statistics`, `triggerCount`, etc).
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-12-12 14:36:56 +01:00
committed by GitHub
parent 19e88ec8a1
commit 1d870412ca
4 changed files with 63 additions and 14 deletions

View File

@@ -0,0 +1,53 @@
import Container from 'typedi';
import { ExecutionRepository } from '@db/repositories/execution.repository';
import { ExecutionDataRepository } from '@db/repositories/executionData.repository';
import * as testDb from '../../shared/testDb';
import { createWorkflow } from '../../shared/db/workflows';
describe('ExecutionRepository', () => {
beforeAll(async () => {
await testDb.init();
});
beforeEach(async () => {
await testDb.truncate(['Workflow', 'Execution']);
});
afterAll(async () => {
await testDb.terminate();
});
describe('createNewExecution', () => {
it('should save execution data', async () => {
const executionRepo = Container.get(ExecutionRepository);
const workflow = await createWorkflow();
const executionId = await executionRepo.createNewExecution({
workflowId: workflow.id,
data: {
resultData: {},
},
workflowData: workflow,
mode: 'manual',
startedAt: new Date(),
status: 'new',
finished: false,
});
expect(executionId).toBeDefined();
const executionEntity = await executionRepo.findOneBy({ id: executionId });
expect(executionEntity?.id).toEqual(executionId);
expect(executionEntity?.workflowId).toEqual(workflow.id);
expect(executionEntity?.status).toEqual('new');
const executionDataRepo = Container.get(ExecutionDataRepository);
const executionData = await executionDataRepo.findOneBy({ executionId });
expect(executionData?.workflowData).toEqual({
connections: workflow.connections,
nodes: workflow.nodes,
name: workflow.name,
});
expect(executionData?.data).toEqual('[{"resultData":"1"},{}]');
});
});
});