From 99c7ecfa82451a44d8b60a4810f02732dfec9b6f Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Mon, 12 May 2025 18:06:10 +1000 Subject: [PATCH] Remove unnecessary copy of litegraph objects --- src/scripts/app.ts | 3 ++- src/services/subgraphService.ts | 17 ++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/scripts/app.ts b/src/scripts/app.ts index 8dc1ab3d2..d8cb5642c 100644 --- a/src/scripts/app.ts +++ b/src/scripts/app.ts @@ -772,7 +772,8 @@ export class ComfyApp { // Register the subgraph - adds type wrapper for Litegraph's `createNode` factory this.graph.events.addEventListener('subgraph-created', (e) => { try { - useSubgraphService().registerNewSubgraph(e.detail) + const { subgraph, data } = e.detail + useSubgraphService().registerNewSubgraph(subgraph, data) } catch (err) { console.error('Failed to register subgraph', err) useToastStore().add({ diff --git a/src/services/subgraphService.ts b/src/services/subgraphService.ts index 2c01351a1..2b59041a0 100644 --- a/src/services/subgraphService.ts +++ b/src/services/subgraphService.ts @@ -12,9 +12,6 @@ import { useNodeDefStore } from '@/stores/nodeDefStore' import { useLitegraphService } from './litegraphService' export const useSubgraphService = () => { - /** @todo Move to store */ - const subgraphs = new Map() - /** Loads a single subgraph definition and registers it with the node def store */ const deserialiseSubgraph = ( subgraph: Subgraph, @@ -63,7 +60,7 @@ export const useSubgraphService = () => { for (const subgraphData of graphData.definitions.subgraphs) { const subgraph = - subgraphs.get(subgraphData.id) ?? + comfyApp.graph.subgraphs.get(subgraphData.id) ?? comfyApp.graph.createSubgraph(subgraphData as ExportedSubgraph) // @ts-expect-error Zod @@ -72,10 +69,16 @@ export const useSubgraphService = () => { } /** Registers a new subgraph (e.g. user converted from nodes) */ - const registerNewSubgraph = (subgraph: Subgraph) => { - subgraphs.set(subgraph.id, subgraph) + const registerNewSubgraph = ( + subgraph: Subgraph, + exportedSubgraph: ExportedSubgraph + ) => { + if (comfyApp.graph.subgraphs.has(subgraph.id)) { + console.debug(`Subgraph ${subgraph.id} already registered`) + return + } - deserialiseSubgraph(subgraph, subgraph.asSerialisable()) + deserialiseSubgraph(subgraph, exportedSubgraph) } return {