mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
perf(core): Batch items sent in runonceforeachitem mode (no-changelog) (#11870)
Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
@@ -10,7 +10,7 @@ import { ExecutionError } from '@/js-task-runner/errors/execution-error';
|
||||
import { ValidationError } from '@/js-task-runner/errors/validation-error';
|
||||
import type { JSExecSettings } from '@/js-task-runner/js-task-runner';
|
||||
import { JsTaskRunner } from '@/js-task-runner/js-task-runner';
|
||||
import type { DataRequestResponse } from '@/runner-types';
|
||||
import type { DataRequestResponse, InputDataChunkDefinition } from '@/runner-types';
|
||||
import type { Task } from '@/task-runner';
|
||||
|
||||
import {
|
||||
@@ -95,17 +95,19 @@ describe('JsTaskRunner', () => {
|
||||
inputItems,
|
||||
settings,
|
||||
runner,
|
||||
chunk,
|
||||
}: {
|
||||
code: string;
|
||||
inputItems: IDataObject[];
|
||||
settings?: Partial<JSExecSettings>;
|
||||
|
||||
runner?: JsTaskRunner;
|
||||
chunk?: InputDataChunkDefinition;
|
||||
}) => {
|
||||
return await execTaskWithParams({
|
||||
task: newTaskWithSettings({
|
||||
code,
|
||||
nodeMode: 'runOnceForEachItem',
|
||||
chunk,
|
||||
...settings,
|
||||
}),
|
||||
taskData: newDataRequestResponse(inputItems.map(wrapIntoJson)),
|
||||
@@ -509,6 +511,28 @@ describe('JsTaskRunner', () => {
|
||||
);
|
||||
});
|
||||
|
||||
describe('chunked execution', () => {
|
||||
it('should use correct index for each item', async () => {
|
||||
const outcome = await executeForEachItem({
|
||||
code: 'return { ...$json, idx: $itemIndex }',
|
||||
inputItems: [{ a: 1 }, { b: 2 }, { c: 3 }],
|
||||
chunk: {
|
||||
startIndex: 100,
|
||||
count: 3,
|
||||
},
|
||||
});
|
||||
|
||||
expect(outcome).toEqual({
|
||||
result: [
|
||||
withPairedItem(100, wrapIntoJson({ a: 1, idx: 100 })),
|
||||
withPairedItem(101, wrapIntoJson({ b: 2, idx: 101 })),
|
||||
withPairedItem(102, wrapIntoJson({ c: 3, idx: 102 })),
|
||||
],
|
||||
customData: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should return static items', async () => {
|
||||
const outcome = await executeForEachItem({
|
||||
code: 'return {json: {b: 1}}',
|
||||
@@ -801,7 +825,6 @@ describe('JsTaskRunner', () => {
|
||||
code: 'unknown; return []',
|
||||
nodeMode: 'runOnceForAllItems',
|
||||
continueOnFail: false,
|
||||
mode: 'manual',
|
||||
workflowMode: 'manual',
|
||||
});
|
||||
runner.runningTasks.set(taskId, task);
|
||||
|
||||
Reference in New Issue
Block a user