perf: greatly improve workflow loading performance

This commit is contained in:
Alex Grozav 2024-11-07 15:49:15 +02:00
parent 6439291738
commit 5d7ab5b90b
2 changed files with 18 additions and 7 deletions

View file

@ -612,12 +612,11 @@ export function useCanvasOperations({ router }: { router: ReturnType<typeof useR
}
void nextTick(() => {
workflowsStore.setNodePristine(nodeData.name, true);
if (!options.keepPristine) {
uiStore.stateIsDirty = true;
}
workflowsStore.setNodePristine(nodeData.name, true);
nodeHelpers.matchCredentials(nodeData);
nodeHelpers.updateNodeParameterIssues(nodeData);
nodeHelpers.updateNodeCredentialIssues(nodeData);
@ -1381,11 +1380,17 @@ export function useCanvasOperations({ router }: { router: ReturnType<typeof useR
async function initializeWorkspace(data: IWorkflowDb) {
// Set workflow data
workflowHelpers.initState(data);
workflowsStore.workflow.nodes = data.nodes;
workflowsStore.workflow.connections = data.connections;
// Add nodes and connections
await addNodes(data.nodes, { keepPristine: true });
await addConnections(mapLegacyConnectionsToCanvasConnections(data.connections, data.nodes), {
keepPristine: true,
void nextTick(() => {
workflowsStore.workflow.nodes.forEach((node) => {
workflowsStore.setNodeMetadata(node.name, { pristine: true });
nodeHelpers.matchCredentials(node);
nodeHelpers.updateNodeParameterIssues(node);
nodeHelpers.updateNodeCredentialIssues(node);
nodeHelpers.updateNodeInputIssues(node);
});
});
}

View file

@ -1109,9 +1109,10 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, () => {
}
workflow.value.nodes.push(nodeData);
// Init node metadata
if (!nodeMetadata.value[nodeData.name]) {
nodeMetadata.value[nodeData.name] = {} as INodeMetadata;
setNodeMetadata(nodeData.name, {} as INodeMetadata);
}
}
@ -1557,6 +1558,10 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, () => {
return url.toString();
}
function setNodeMetadata(nodeName: string, metadata: INodeMetadata): void {
nodeMetadata.value[nodeName] = metadata;
}
function setNodePristine(nodeName: string, isPristine: boolean): void {
nodeMetadata.value[nodeName].pristine = isPristine;
}
@ -1749,6 +1754,7 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, () => {
deleteExecution,
addToCurrentExecutions,
getBinaryUrl,
setNodeMetadata,
setNodePristine,
resetChatMessages,
appendChatMessage,