feat: Update Workflow class usage on the Frontend for better performance (no-changelog) (#17680)

This commit is contained in:
Alex Grozav
2025-08-04 15:04:00 +03:00
committed by GitHub
parent ff8531d544
commit 279dce639a
66 changed files with 659 additions and 660 deletions

View File

@@ -67,9 +67,9 @@ export class Workflow {
nodes: INodes = {};
connectionsBySourceNode: IConnections;
connectionsBySourceNode: IConnections = {};
connectionsByDestinationNode: IConnections;
connectionsByDestinationNode: IConnections = {};
nodeTypes: INodeTypes;
@@ -77,7 +77,7 @@ export class Workflow {
active: boolean;
settings: IWorkflowSettings;
settings: IWorkflowSettings = {};
readonly timezone: string;
@@ -93,15 +93,9 @@ export class Workflow {
this.id = parameters.id as string; // @tech_debt Ensure this is not optional
this.name = parameters.name;
this.nodeTypes = parameters.nodeTypes;
this.pinData = parameters.pinData;
// Save nodes in workflow as object to be able to get the
// nodes easily by its name.
// Also directly add the default values of the node type.
let nodeType: INodeType | undefined;
for (const node of parameters.nodes) {
this.nodes[node.name] = node;
nodeType = this.nodeTypes.getByNameAndVersion(node.type, node.typeVersion);
if (nodeType === undefined) {
@@ -127,10 +121,11 @@ export class Workflow {
);
node.parameters = nodeParameters !== null ? nodeParameters : {};
}
this.connectionsBySourceNode = parameters.connections;
// Save also the connections by the destination nodes
this.connectionsByDestinationNode = mapConnectionsByDestination(parameters.connections);
this.setNodes(parameters.nodes);
this.setConnections(parameters.connections);
this.setPinData(parameters.pinData);
this.setSettings(parameters.settings ?? {});
this.active = parameters.active || false;
@@ -138,12 +133,32 @@ export class Workflow {
ignoreEmptyOnFirstChild: true,
});
this.settings = parameters.settings || {};
this.timezone = this.settings.timezone ?? getGlobalState().defaultTimezone;
this.expression = new Expression(this);
}
// Save nodes in workflow as object to be able to get the nodes easily by their name.
setNodes(nodes: INode[]) {
this.nodes = {};
for (const node of nodes) {
this.nodes[node.name] = node;
}
}
setConnections(connections: IConnections) {
this.connectionsBySourceNode = connections;
this.connectionsByDestinationNode = mapConnectionsByDestination(this.connectionsBySourceNode);
}
setPinData(pinData: IPinData | undefined) {
this.pinData = pinData;
}
setSettings(settings: IWorkflowSettings) {
this.settings = settings;
}
overrideStaticData(staticData?: IDataObject) {
this.staticData = ObservableObject.create(staticData || {}, undefined, {
ignoreEmptyOnFirstChild: true,
@@ -471,9 +486,6 @@ export class Workflow {
}
}
}
// Use the updated connections to create updated connections by destination nodes
this.connectionsByDestinationNode = mapConnectionsByDestination(this.connectionsBySourceNode);
}
/**