feat(Split In Batches Node): Make it easy to combine processed data (#5655)

feat(SplitInBatches Node): Make it easy to combine processed data
This commit is contained in:
Jan Oberhauser
2023-03-14 18:42:41 +01:00
committed by GitHub
parent de1db927cb
commit 2f7639e9e4
2 changed files with 226 additions and 5 deletions

View File

@@ -20,7 +20,9 @@ export class SplitInBatches implements INodeType {
color: '#007755',
},
inputs: ['main'],
outputs: ['main'],
// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong
outputs: ['main', 'main'],
outputNames: ['loop', 'done'],
properties: [
{
displayName:
@@ -84,8 +86,11 @@ export class SplitInBatches implements INodeType {
// Get the items which should be returned
returnItems.push.apply(returnItems, items.splice(0, batchSize));
// Set the other items to be saved in the context to return at later runs
// Save the incoming items to be able to return them for later runs
nodeContext.items = [...items];
// Reset processedItems as they get only added starting from the first iteration
nodeContext.processedItems = [];
} else {
// The node has been called before. So return the next batch of items.
nodeContext.currentRunIndex += 1;
@@ -125,6 +130,20 @@ export class SplitInBatches implements INodeType {
return addSourceOverwrite(item.pairedItem);
}
const sourceOverwrite = this.getInputSourceData();
const newItems = items.map((item, index) => {
return {
...item,
pairedItem: {
sourceOverwrite,
item: index,
},
};
});
nodeContext.processedItems = [...nodeContext.processedItems, ...newItems];
returnItems.map((item) => {
item.pairedItem = getPairedItemInformation(item);
});
@@ -133,10 +152,9 @@ export class SplitInBatches implements INodeType {
nodeContext.noItemsLeft = nodeContext.items.length === 0;
if (returnItems.length === 0) {
// No data left to return so stop execution of the branch
return null;
return [[], nodeContext.processedItems];
}
return [returnItems];
return [returnItems, []];
}
}