mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(editor): improve expression and parameters performance (#3874)
* fix expr perf issue * refactor a bit
This commit is contained in:
@@ -55,6 +55,9 @@ import { isEqual } from 'lodash';
|
||||
import mixins from 'vue-typed-mixins';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
|
||||
let cachedWorkflowKey: string | null = '';
|
||||
let cachedWorkflow: Workflow | null = null;
|
||||
|
||||
export const workflowHelpers = mixins(
|
||||
externalHooks,
|
||||
nodeHelpers,
|
||||
@@ -317,11 +320,20 @@ export const workflowHelpers = mixins(
|
||||
return nodeTypes;
|
||||
},
|
||||
|
||||
// Returns a workflow instance.
|
||||
getWorkflow (nodes?: INodeUi[], connections?: IConnections, copyData?: boolean): Workflow {
|
||||
nodes = nodes || this.getNodes();
|
||||
connections = connections || (this.$store.getters.allConnections as IConnections);
|
||||
getCurrentWorkflow(copyData?: boolean): Workflow {
|
||||
const nodes = this.getNodes();
|
||||
const connections = (this.$store.getters.allConnections as IConnections);
|
||||
const cacheKey = JSON.stringify({nodes, connections});
|
||||
if (cachedWorkflow && cacheKey === cachedWorkflowKey) {
|
||||
return cachedWorkflow;
|
||||
}
|
||||
cachedWorkflowKey = cacheKey;
|
||||
|
||||
return this.getWorkflow(nodes, connections, copyData);
|
||||
},
|
||||
|
||||
// Returns a workflow instance.
|
||||
getWorkflow (nodes: INodeUi[], connections: IConnections, copyData?: boolean): Workflow {
|
||||
const nodeTypes = this.getNodeTypes();
|
||||
let workflowId = this.$store.getters.workflowId;
|
||||
if (workflowId === PLACEHOLDER_EMPTY_WORKFLOW_ID) {
|
||||
@@ -330,7 +342,7 @@ export const workflowHelpers = mixins(
|
||||
|
||||
const workflowName = this.$store.getters.workflowName;
|
||||
|
||||
return new Workflow({
|
||||
cachedWorkflow = new Workflow({
|
||||
id: workflowId,
|
||||
name: workflowName,
|
||||
nodes: copyData ? JSON.parse(JSON.stringify(nodes)) : nodes,
|
||||
@@ -340,6 +352,8 @@ export const workflowHelpers = mixins(
|
||||
settings: this.$store.getters.workflowSettings,
|
||||
pinData: this.$store.getters.pinData,
|
||||
});
|
||||
|
||||
return cachedWorkflow;
|
||||
},
|
||||
|
||||
// Returns the currently loaded workflow as JSON.
|
||||
@@ -503,7 +517,7 @@ export const workflowHelpers = mixins(
|
||||
const itemIndex = 0;
|
||||
const inputName = 'main';
|
||||
const activeNode = this.$store.getters.activeNode;
|
||||
const workflow = this.getWorkflow();
|
||||
const workflow = this.getCurrentWorkflow();
|
||||
const parentNode = workflow.getParentNodes(activeNode.name, inputName, 1);
|
||||
const executionData = this.$store.getters.getWorkflowExecution as IExecutionResponse | null;
|
||||
|
||||
@@ -584,7 +598,7 @@ export const workflowHelpers = mixins(
|
||||
const returnData = this.resolveParameter(parameters) as IDataObject;
|
||||
|
||||
if (typeof returnData['__xxxxxxx__'] === 'object') {
|
||||
const workflow = this.getWorkflow();
|
||||
const workflow = this.getCurrentWorkflow();
|
||||
return workflow.expression.convertObjectValueToString(returnData['__xxxxxxx__'] as object);
|
||||
}
|
||||
return returnData['__xxxxxxx__'];
|
||||
|
||||
Reference in New Issue
Block a user