@@ -23,6 +23,12 @@ let availableSchedulers = [];
2323let availableSessions = [ "None" ] ;
2424let availableConfigs = [ "None" ] ;
2525
26+ // Cache-loaded flags for fetchers that can't use null-check
27+ // (their initial values are already non-null arrays)
28+ let _modelListsLoaded = false ;
29+ let _sessionsLoaded = false ;
30+ let _configsLoaded = false ;
31+
2632// Track all active ConfigBuilder nodes for refresh
2733let activeConfigBuilderNodes = new Set ( ) ;
2834
@@ -46,8 +52,15 @@ export function clearAllCaches() {
4652 dualClipTypes = [ ] ;
4753 availableSamplers = [ ] ;
4854 availableSchedulers = [ ] ;
55+ _modelListsLoaded = false ;
56+ _sessionsLoaded = false ;
57+ _configsLoaded = false ;
4958}
5059
60+ // Targeted cache invalidation for when specific data changes
61+ export function clearConfigsCache ( ) { _configsLoaded = false ; }
62+ export function clearSessionsCache ( ) { _sessionsLoaded = false ; }
63+
5164export async function refreshAllConfigBuilders ( ) {
5265 console . log ( "[ConfigBuilder] 🔄 Refreshing all Config Builder nodes..." ) ;
5366 clearAllCaches ( ) ;
@@ -156,6 +169,8 @@ export async function getModelFolders() {
156169// --- UNIFIED MODEL LISTS (for GGUF, Diffusion Models, Text Encoders) ---
157170
158171export async function getModelLists ( ) {
172+ // Return cached data if already loaded (cleared by clearAllCaches on explicit refresh)
173+ if ( _modelListsLoaded ) return ;
159174 // Fetch all model lists from the unified endpoint
160175 try {
161176 const resp = await fetch ( "/configbuilder/model_lists" , {
@@ -201,6 +216,7 @@ export async function getModelLists() {
201216 if ( availableGGUFModels . length === 0 ) {
202217 console . log ( `[ConfigBuilder] ℹ️ No GGUF models found. Install ComfyUI-GGUF and place .gguf files in the unet_gguf folder.` ) ;
203218 }
219+ _modelListsLoaded = true ;
204220 return data ;
205221 } catch ( e ) {
206222 console . error ( "[ConfigBuilder] Error fetching model lists:" , e ) ;
@@ -222,28 +238,35 @@ export function getAvailableSamplers() { return availableSamplers || []; }
222238export function getAvailableSchedulers ( ) { return availableSchedulers || [ ] ; }
223239
224240export async function getAvailableSessions ( ) {
241+ // Return cached sessions if already loaded (cleared by clearAllCaches on explicit refresh)
242+ if ( _sessionsLoaded ) return availableSessions ;
225243 try {
226244 const resp = await fetch ( "/object_info" , { headers : { "X-Config-Builder-Internal" : "true" } } ) ;
227245 const objectInfo = await resp . json ( ) ;
228246 for ( const nodeType in objectInfo ) {
229247 const nodeDef = objectInfo [ nodeType ] ;
230248 if ( nodeType === "UltimateConfigBuilder" && nodeDef . input ?. required ?. load_session ) {
231249 availableSessions = nodeDef . input . required . load_session [ 0 ] ;
250+ _sessionsLoaded = true ;
232251 return availableSessions ;
233252 }
234253 }
235254 } catch ( e ) { console . error ( "[ConfigBuilder] Error fetching sessions:" , e ) ; }
255+ _sessionsLoaded = true ;
236256 return availableSessions ;
237257}
238258
239259export async function getAvailableConfigs ( ) {
260+ // Return cached configs if already loaded (use clearConfigsCache() to force refresh)
261+ if ( _configsLoaded ) return availableConfigs ;
240262 try {
241263 const resp = await fetch ( "/configbuilder/list_configs" ) ;
242264 if ( resp . ok ) {
243265 const files = await resp . json ( ) ;
244266 availableConfigs = files . length > 0 ? files : [ "None" ] ;
245267 }
246268 } catch ( e ) { console . error ( "[ConfigBuilder] Error fetching configs:" , e ) ; }
269+ _configsLoaded = true ;
247270 return availableConfigs ;
248271}
249272
0 commit comments