mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-08 06:30:04 +00:00
Fix partial execution inside subgraphs (#6487)
`getExecutionIdsForSelectedNodes` is only used for partial execution. The prior implementation solved the wrong problem. Given a list of nodes, it would explore into subgraphs and return a list of partial ExecutionIds for all contained nodes. Because this does not resolve the partial execution path to the current subgraph, this is incorrect when the current graph is not the root graph. Woefully, this incorrect functionality is never useful because the recursive exploration only applies to subgraph nodes which never satisfy the outputNode filter applied by the parent function. An extra function is used to correctly append the parent execution path, but the existing, probably never useful code for recursively collecting children is otherwise left in place. Resolves #6480 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6487-Fix-partial-execution-inside-subgraphs-29d6d73d36508197924bfb3a0fb6699e) by [Unito](https://www.unito.io)
This commit is contained in:
@@ -541,8 +541,16 @@ export function collectFromNodes<T = LGraphNode, C = void>(
|
||||
* @returns Array of execution IDs for selected nodes and all nodes within selected subgraphs
|
||||
*/
|
||||
export function getExecutionIdsForSelectedNodes(
|
||||
selectedNodes: LGraphNode[]
|
||||
selectedNodes: LGraphNode[],
|
||||
startGraph = selectedNodes[0]?.graph
|
||||
): NodeExecutionId[] {
|
||||
if (!startGraph) return []
|
||||
const rootGraph = startGraph.rootGraph
|
||||
const parentPath = startGraph.isRootGraph
|
||||
? ''
|
||||
: findPartialExecutionPathToGraph(startGraph, rootGraph)
|
||||
if (parentPath === undefined) return []
|
||||
|
||||
return collectFromNodes<NodeExecutionId, string>(selectedNodes, {
|
||||
collector: (node, parentExecutionId) => {
|
||||
const nodeId = String(node.id)
|
||||
@@ -552,7 +560,22 @@ export function getExecutionIdsForSelectedNodes(
|
||||
const nodeId = String(node.id)
|
||||
return parentExecutionId ? `${parentExecutionId}:${nodeId}` : nodeId
|
||||
},
|
||||
initialContext: '',
|
||||
initialContext: parentPath,
|
||||
expandSubgraphs: true
|
||||
})
|
||||
}
|
||||
|
||||
function findPartialExecutionPathToGraph(
|
||||
target: LGraph,
|
||||
root: LGraph
|
||||
): string | undefined {
|
||||
for (const node of root.nodes) {
|
||||
if (!node.isSubgraphNode()) continue
|
||||
|
||||
if (node.subgraph === target) return `${node.id}`
|
||||
|
||||
const subpath = findPartialExecutionPathToGraph(target, node.subgraph)
|
||||
if (subpath !== undefined) return node.id + ':' + subpath
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user