@@ -675,21 +675,39 @@ async def lookup_lora_metadata_endpoint(request):
675675 }, status = 400 )
676676
677677 print (f"[ConfigBuilder] 🔍 Full metadata lookup request for: { lora_name } " )
678-
678+
679+ # Check disk cache first to avoid expensive SHA256 hashing
680+ output_dir = folder_paths .get_output_directory ()
681+ model_data_dir = os .path .join (output_dir , "benchmarks" , "model-data" , lora_name .replace ("/" , "_" ).replace ("\\ " , "_" ).replace (".safetensors" , "" ))
682+ metadata_file = os .path .join (model_data_dir , "metadata.json" )
683+
684+ if os .path .exists (metadata_file ):
685+ try :
686+ cached = load_json_from_file (metadata_file )
687+ if cached and cached .get ("name" ):
688+ print (f"[ConfigBuilder] ✅ Using cached metadata for: { lora_name } " )
689+ return web .json_response ({
690+ "metadata" : cached ,
691+ "saved_to" : metadata_file ,
692+ "cached" : True
693+ })
694+ except Exception :
695+ pass # Cache miss or corrupt file - fall through to fresh lookup
696+
679697 # Get the full path to the LoRA file
680698 lora_path = folder_paths .get_full_path ("loras" , lora_name )
681-
699+
682700 if lora_path is None :
683701 return web .json_response ({
684702 "error" : f"LoRA file not found: { lora_name } "
685703 }, status = 404 )
686-
687- # Calculate the hash
704+
705+ # Calculate the hash (expensive - only when not cached)
688706 lora_hash = calculate_sha256 (lora_path )
689707 short_hash = lora_hash [:10 ] # First 10 characters for short hash
690-
708+
691709 print (f"[ConfigBuilder] 📊 Hash calculated: { short_hash } " )
692-
710+
693711 # Fetch metadata from CivitAI
694712 model_info = get_model_version_info (lora_hash )
695713
@@ -768,6 +786,24 @@ async def lookup_model_metadata_endpoint(request):
768786
769787 print (f"[ConfigBuilder] 🔍 Full metadata lookup request for model: { model_name } (type: { model_type } )" )
770788
789+ # Check disk cache first to avoid expensive SHA256 hashing
790+ output_dir = folder_paths .get_output_directory ()
791+ model_data_dir = os .path .join (output_dir , "benchmarks" , "model-data" , model_name .replace ("/" , "_" ).replace ("\\ " , "_" ).replace (".safetensors" , "" ).replace (".ckpt" , "" ).replace (".gguf" , "" ))
792+ metadata_file = os .path .join (model_data_dir , "metadata.json" )
793+
794+ if os .path .exists (metadata_file ):
795+ try :
796+ cached = load_json_from_file (metadata_file )
797+ if cached and cached .get ("name" ):
798+ print (f"[ConfigBuilder] ✅ Using cached metadata for model: { model_name } " )
799+ return web .json_response ({
800+ "metadata" : cached ,
801+ "saved_to" : metadata_file ,
802+ "cached" : True
803+ })
804+ except Exception :
805+ pass # Cache miss or corrupt file - fall through to fresh lookup
806+
771807 # Resolve the full path based on model type
772808 model_path = None
773809 if model_type == "gguf" :
@@ -787,7 +823,7 @@ async def lookup_model_metadata_endpoint(request):
787823 "error" : f"Model file not found: { model_name } "
788824 }, status = 404 )
789825
790- # Calculate the hash
826+ # Calculate the hash (expensive - only when not cached)
791827 model_hash = calculate_sha256 (model_path )
792828 short_hash = model_hash [:10 ]
793829
0 commit comments