mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(editor): improve expression and parameters performance (#3874)
* fix expr perf issue * refactor a bit
This commit is contained in:
parent
762b422488
commit
3608d132c0
|
@ -51,7 +51,7 @@ export default mixins(
|
||||||
let runIndex = 0;
|
let runIndex = 0;
|
||||||
|
|
||||||
const executedWorkflow: IExecutionResponse | null = this.$store.getters.getWorkflowExecution;
|
const executedWorkflow: IExecutionResponse | null = this.$store.getters.getWorkflowExecution;
|
||||||
const workflow = this.getWorkflow();
|
const workflow = this.getCurrentWorkflow();
|
||||||
const activeNode: INodeUi | null = this.$store.getters.activeNode;
|
const activeNode: INodeUi | null = this.$store.getters.activeNode;
|
||||||
const parentNode = workflow.getParentNodes(activeNode!.name, inputName, 1);
|
const parentNode = workflow.getParentNodes(activeNode!.name, inputName, 1);
|
||||||
const nodeConnection = workflow.getNodeConnectionIndexes(activeNode!.name, parentNode[0]) || {
|
const nodeConnection = workflow.getNodeConnectionIndexes(activeNode!.name, parentNode[0]) || {
|
||||||
|
|
|
@ -56,7 +56,7 @@ export default mixins(
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
workflow (): Workflow {
|
workflow (): Workflow {
|
||||||
return this.getWorkflow();
|
return this.getCurrentWorkflow();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
|
|
@ -385,7 +385,7 @@ export default mixins(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setSubtitle() {
|
setSubtitle() {
|
||||||
const nodeSubtitle = this.getNodeSubtitle(this.data, this.nodeType, this.getWorkflow()) || '';
|
const nodeSubtitle = this.getNodeSubtitle(this.data, this.nodeType, this.getCurrentWorkflow()) || '';
|
||||||
|
|
||||||
this.nodeSubtitle = nodeSubtitle.includes(CUSTOM_API_CALL_KEY)
|
this.nodeSubtitle = nodeSubtitle.includes(CUSTOM_API_CALL_KEY)
|
||||||
? ''
|
? ''
|
||||||
|
|
|
@ -224,7 +224,7 @@ export default mixins(
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
workflow(): Workflow {
|
workflow(): Workflow {
|
||||||
return this.getWorkflow();
|
return this.getCurrentWorkflow();
|
||||||
},
|
},
|
||||||
parentNodes(): string[] {
|
parentNodes(): string[] {
|
||||||
if (this.activeNode) {
|
if (this.activeNode) {
|
||||||
|
@ -344,7 +344,7 @@ export default mixins(
|
||||||
|
|
||||||
this.$store.commit('ui/setNDVSessionId');
|
this.$store.commit('ui/setNDVSessionId');
|
||||||
this.$externalHooks().run('dataDisplay.nodeTypeChanged', {
|
this.$externalHooks().run('dataDisplay.nodeTypeChanged', {
|
||||||
nodeSubtitle: this.getNodeSubtitle(node, this.activeNodeType, this.getWorkflow()),
|
nodeSubtitle: this.getNodeSubtitle(node, this.activeNodeType, this.getCurrentWorkflow()),
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
|
@ -685,7 +685,7 @@ export default mixins(
|
||||||
return shortPath.join('.');
|
return shortPath.join('.');
|
||||||
},
|
},
|
||||||
workflow (): Workflow {
|
workflow (): Workflow {
|
||||||
return this.getWorkflow();
|
return this.getCurrentWorkflow();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
|
@ -75,7 +75,7 @@ export default mixins(
|
||||||
return this.getFilterResults(this.variableFilter.toLowerCase(), 0);
|
return this.getFilterResults(this.variableFilter.toLowerCase(), 0);
|
||||||
},
|
},
|
||||||
workflow (): Workflow {
|
workflow (): Workflow {
|
||||||
return this.getWorkflow();
|
return this.getCurrentWorkflow();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
|
@ -221,8 +221,7 @@ export const pushConnection = mixins(
|
||||||
|
|
||||||
const runDataExecutedErrorMessage = this.$getExecutionError(runDataExecuted.data.resultData.error);
|
const runDataExecutedErrorMessage = this.$getExecutionError(runDataExecuted.data.resultData.error);
|
||||||
|
|
||||||
// @ts-ignore
|
const workflow = this.getCurrentWorkflow();
|
||||||
const workflow = this.getWorkflow();
|
|
||||||
if (runDataExecuted.waitTill !== undefined) {
|
if (runDataExecuted.waitTill !== undefined) {
|
||||||
const {
|
const {
|
||||||
activeExecutionId,
|
activeExecutionId,
|
||||||
|
|
|
@ -55,6 +55,9 @@ import { isEqual } from 'lodash';
|
||||||
import mixins from 'vue-typed-mixins';
|
import mixins from 'vue-typed-mixins';
|
||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
|
|
||||||
|
let cachedWorkflowKey: string | null = '';
|
||||||
|
let cachedWorkflow: Workflow | null = null;
|
||||||
|
|
||||||
export const workflowHelpers = mixins(
|
export const workflowHelpers = mixins(
|
||||||
externalHooks,
|
externalHooks,
|
||||||
nodeHelpers,
|
nodeHelpers,
|
||||||
|
@ -317,11 +320,20 @@ export const workflowHelpers = mixins(
|
||||||
return nodeTypes;
|
return nodeTypes;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Returns a workflow instance.
|
getCurrentWorkflow(copyData?: boolean): Workflow {
|
||||||
getWorkflow (nodes?: INodeUi[], connections?: IConnections, copyData?: boolean): Workflow {
|
const nodes = this.getNodes();
|
||||||
nodes = nodes || this.getNodes();
|
const connections = (this.$store.getters.allConnections as IConnections);
|
||||||
connections = 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();
|
const nodeTypes = this.getNodeTypes();
|
||||||
let workflowId = this.$store.getters.workflowId;
|
let workflowId = this.$store.getters.workflowId;
|
||||||
if (workflowId === PLACEHOLDER_EMPTY_WORKFLOW_ID) {
|
if (workflowId === PLACEHOLDER_EMPTY_WORKFLOW_ID) {
|
||||||
|
@ -330,7 +342,7 @@ export const workflowHelpers = mixins(
|
||||||
|
|
||||||
const workflowName = this.$store.getters.workflowName;
|
const workflowName = this.$store.getters.workflowName;
|
||||||
|
|
||||||
return new Workflow({
|
cachedWorkflow = new Workflow({
|
||||||
id: workflowId,
|
id: workflowId,
|
||||||
name: workflowName,
|
name: workflowName,
|
||||||
nodes: copyData ? JSON.parse(JSON.stringify(nodes)) : nodes,
|
nodes: copyData ? JSON.parse(JSON.stringify(nodes)) : nodes,
|
||||||
|
@ -340,6 +352,8 @@ export const workflowHelpers = mixins(
|
||||||
settings: this.$store.getters.workflowSettings,
|
settings: this.$store.getters.workflowSettings,
|
||||||
pinData: this.$store.getters.pinData,
|
pinData: this.$store.getters.pinData,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return cachedWorkflow;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Returns the currently loaded workflow as JSON.
|
// Returns the currently loaded workflow as JSON.
|
||||||
|
@ -503,7 +517,7 @@ export const workflowHelpers = mixins(
|
||||||
const itemIndex = 0;
|
const itemIndex = 0;
|
||||||
const inputName = 'main';
|
const inputName = 'main';
|
||||||
const activeNode = this.$store.getters.activeNode;
|
const activeNode = this.$store.getters.activeNode;
|
||||||
const workflow = this.getWorkflow();
|
const workflow = this.getCurrentWorkflow();
|
||||||
const parentNode = workflow.getParentNodes(activeNode.name, inputName, 1);
|
const parentNode = workflow.getParentNodes(activeNode.name, inputName, 1);
|
||||||
const executionData = this.$store.getters.getWorkflowExecution as IExecutionResponse | null;
|
const executionData = this.$store.getters.getWorkflowExecution as IExecutionResponse | null;
|
||||||
|
|
||||||
|
@ -584,7 +598,7 @@ export const workflowHelpers = mixins(
|
||||||
const returnData = this.resolveParameter(parameters) as IDataObject;
|
const returnData = this.resolveParameter(parameters) as IDataObject;
|
||||||
|
|
||||||
if (typeof returnData['__xxxxxxx__'] === 'object') {
|
if (typeof returnData['__xxxxxxx__'] === 'object') {
|
||||||
const workflow = this.getWorkflow();
|
const workflow = this.getCurrentWorkflow();
|
||||||
return workflow.expression.convertObjectValueToString(returnData['__xxxxxxx__'] as object);
|
return workflow.expression.convertObjectValueToString(returnData['__xxxxxxx__'] as object);
|
||||||
}
|
}
|
||||||
return returnData['__xxxxxxx__'];
|
return returnData['__xxxxxxx__'];
|
||||||
|
|
|
@ -60,7 +60,7 @@ export const workflowRun = mixins(
|
||||||
return response;
|
return response;
|
||||||
},
|
},
|
||||||
async runWorkflow (nodeName?: string, source?: string): Promise<IExecutionPushResponse | undefined> {
|
async runWorkflow (nodeName?: string, source?: string): Promise<IExecutionPushResponse | undefined> {
|
||||||
const workflow = this.getWorkflow();
|
const workflow = this.getCurrentWorkflow();
|
||||||
|
|
||||||
if (this.$store.getters.isActionActive('workflowRunning') === true) {
|
if (this.$store.getters.isActionActive('workflowRunning') === true) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -927,7 +927,7 @@ export default mixins(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const workflow = this.getWorkflow();
|
const workflow = this.getCurrentWorkflow();
|
||||||
|
|
||||||
if (!workflow.connectionsByDestinationNode.hasOwnProperty(lastSelectedNode.name)) {
|
if (!workflow.connectionsByDestinationNode.hasOwnProperty(lastSelectedNode.name)) {
|
||||||
return;
|
return;
|
||||||
|
@ -949,7 +949,7 @@ export default mixins(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const workflow = this.getWorkflow();
|
const workflow = this.getCurrentWorkflow();
|
||||||
|
|
||||||
if (!workflow.connectionsByDestinationNode.hasOwnProperty(lastSelectedNode.name)) {
|
if (!workflow.connectionsByDestinationNode.hasOwnProperty(lastSelectedNode.name)) {
|
||||||
return;
|
return;
|
||||||
|
@ -1036,7 +1036,7 @@ export default mixins(
|
||||||
this.deselectAllNodes();
|
this.deselectAllNodes();
|
||||||
|
|
||||||
// Get all upstream nodes and select them
|
// Get all upstream nodes and select them
|
||||||
const workflow = this.getWorkflow();
|
const workflow = this.getCurrentWorkflow();
|
||||||
for (const nodeName of workflow.getParentNodes(lastSelectedNode.name)) {
|
for (const nodeName of workflow.getParentNodes(lastSelectedNode.name)) {
|
||||||
this.nodeSelectedByName(nodeName);
|
this.nodeSelectedByName(nodeName);
|
||||||
}
|
}
|
||||||
|
@ -1053,7 +1053,7 @@ export default mixins(
|
||||||
this.deselectAllNodes();
|
this.deselectAllNodes();
|
||||||
|
|
||||||
// Get all downstream nodes and select them
|
// Get all downstream nodes and select them
|
||||||
const workflow = this.getWorkflow();
|
const workflow = this.getCurrentWorkflow();
|
||||||
for (const nodeName of workflow.getChildNodes(lastSelectedNode.name)) {
|
for (const nodeName of workflow.getChildNodes(lastSelectedNode.name)) {
|
||||||
this.nodeSelectedByName(nodeName);
|
this.nodeSelectedByName(nodeName);
|
||||||
}
|
}
|
||||||
|
@ -1064,7 +1064,7 @@ export default mixins(
|
||||||
|
|
||||||
pushDownstreamNodes (sourceNodeName: string, margin: number) {
|
pushDownstreamNodes (sourceNodeName: string, margin: number) {
|
||||||
const sourceNode = this.$store.getters.nodesByName[sourceNodeName];
|
const sourceNode = this.$store.getters.nodesByName[sourceNodeName];
|
||||||
const workflow = this.getWorkflow();
|
const workflow = this.getCurrentWorkflow();
|
||||||
const childNodes = workflow.getChildNodes(sourceNodeName);
|
const childNodes = workflow.getChildNodes(sourceNodeName);
|
||||||
for (const nodeName of childNodes) {
|
for (const nodeName of childNodes) {
|
||||||
const node = this.$store.getters.nodesByName[nodeName] as INodeUi;
|
const node = this.$store.getters.nodesByName[nodeName] as INodeUi;
|
||||||
|
@ -2586,7 +2586,7 @@ export default mixins(
|
||||||
});
|
});
|
||||||
|
|
||||||
// Rename the node and update the connections
|
// Rename the node and update the connections
|
||||||
const workflow = this.getWorkflow(undefined, undefined, true);
|
const workflow = this.getCurrentWorkflow(true);
|
||||||
workflow.renameNode(currentName, newName);
|
workflow.renameNode(currentName, newName);
|
||||||
|
|
||||||
// Update also last selected node and exeuction data
|
// Update also last selected node and exeuction data
|
||||||
|
|
Loading…
Reference in a new issue