refactor: Rename LoraScanner methods for consistency and remove deprecated checkpoint methods

This commit is contained in:
Will Miao
2025-07-24 06:25:33 +08:00
parent bf9aa9356b
commit cf9fd2d5c2
4 changed files with 12 additions and 38 deletions

View File

@@ -1257,7 +1257,7 @@ class RecipeRoutes:
if lora.get("isDeleted", False): if lora.get("isDeleted", False):
continue continue
if not self.recipe_scanner._lora_scanner.has_lora_hash(lora.get("hash", "")): if not self.recipe_scanner._lora_scanner.has_hash(lora.get("hash", "")):
continue continue
# Get the strength # Get the strength
@@ -1477,9 +1477,9 @@ class RecipeRoutes:
if 'loras' in recipe: if 'loras' in recipe:
for lora in recipe['loras']: for lora in recipe['loras']:
if 'hash' in lora and lora['hash']: if 'hash' in lora and lora['hash']:
lora['inLibrary'] = self.recipe_scanner._lora_scanner.has_lora_hash(lora['hash'].lower()) lora['inLibrary'] = self.recipe_scanner._lora_scanner.has_hash(lora['hash'].lower())
lora['preview_url'] = self.recipe_scanner._lora_scanner.get_preview_url_by_hash(lora['hash'].lower()) lora['preview_url'] = self.recipe_scanner._lora_scanner.get_preview_url_by_hash(lora['hash'].lower())
lora['localPath'] = self.recipe_scanner._lora_scanner.get_lora_path_by_hash(lora['hash'].lower()) lora['localPath'] = self.recipe_scanner._lora_scanner.get_path_by_hash(lora['hash'].lower())
# Ensure file_url is set (needed by frontend) # Ensure file_url is set (needed by frontend)
if 'file_path' in recipe: if 'file_path' in recipe:

View File

@@ -24,16 +24,3 @@ class CheckpointScanner(ModelScanner):
def get_model_roots(self) -> List[str]: def get_model_roots(self) -> List[str]:
"""Get checkpoint root directories""" """Get checkpoint root directories"""
return config.base_models_roots return config.base_models_roots
# Checkpoint-specific hash index functionality
def has_checkpoint_hash(self, sha256: str) -> bool:
"""Check if a checkpoint with given hash exists"""
return self.has_hash(sha256)
def get_checkpoint_path_by_hash(self, sha256: str) -> str:
"""Get file path for a checkpoint by its hash"""
return self.get_path_by_hash(sha256)
def get_checkpoint_hash_by_path(self, file_path: str) -> str:
"""Get hash for a checkpoint by its file path"""
return self.get_hash_by_path(file_path)

View File

@@ -1,5 +1,5 @@
import logging import logging
from typing import List, Optional from typing import List
from ..utils.models import LoraMetadata from ..utils.models import LoraMetadata
from ..config import config from ..config import config
@@ -28,19 +28,6 @@ class LoraScanner(ModelScanner):
"""Get lora root directories""" """Get lora root directories"""
return config.loras_roots return config.loras_roots
# Lora-specific hash index functionality
def has_lora_hash(self, sha256: str) -> bool:
"""Check if a LoRA with given hash exists"""
return self.has_hash(sha256)
def get_lora_path_by_hash(self, sha256: str) -> Optional[str]:
"""Get file path for a LoRA by its hash"""
return self.get_path_by_hash(sha256)
def get_lora_hash_by_path(self, file_path: str) -> Optional[str]:
"""Get hash for a LoRA by its file path"""
return self.get_hash_by_path(file_path)
async def diagnose_hash_index(self): async def diagnose_hash_index(self):
"""Diagnostic method to verify hash index functionality""" """Diagnostic method to verify hash index functionality"""
print("\n\n*** DIAGNOSING LORA HASH INDEX ***\n\n", file=sys.stderr) print("\n\n*** DIAGNOSING LORA HASH INDEX ***\n\n", file=sys.stderr)

View File

@@ -393,8 +393,8 @@ class RecipeScanner:
if 'hash' in lora and (not lora.get('file_name') or not lora['file_name']): if 'hash' in lora and (not lora.get('file_name') or not lora['file_name']):
hash_value = lora['hash'] hash_value = lora['hash']
if self._lora_scanner.has_lora_hash(hash_value): if self._lora_scanner.has_hash(hash_value):
lora_path = self._lora_scanner.get_lora_path_by_hash(hash_value) lora_path = self._lora_scanner.get_path_by_hash(hash_value)
if lora_path: if lora_path:
file_name = os.path.splitext(os.path.basename(lora_path))[0] file_name = os.path.splitext(os.path.basename(lora_path))[0]
lora['file_name'] = file_name lora['file_name'] = file_name
@@ -465,7 +465,7 @@ class RecipeScanner:
# Count occurrences of each base model # Count occurrences of each base model
for lora in loras: for lora in loras:
if 'hash' in lora: if 'hash' in lora:
lora_path = self._lora_scanner.get_lora_path_by_hash(lora['hash']) lora_path = self._lora_scanner.get_path_by_hash(lora['hash'])
if lora_path: if lora_path:
base_model = await self._get_base_model_for_lora(lora_path) base_model = await self._get_base_model_for_lora(lora_path)
if base_model: if base_model:
@@ -603,9 +603,9 @@ class RecipeScanner:
if 'loras' in item: if 'loras' in item:
for lora in item['loras']: for lora in item['loras']:
if 'hash' in lora and lora['hash']: if 'hash' in lora and lora['hash']:
lora['inLibrary'] = self._lora_scanner.has_lora_hash(lora['hash'].lower()) lora['inLibrary'] = self._lora_scanner.has_hash(lora['hash'].lower())
lora['preview_url'] = self._lora_scanner.get_preview_url_by_hash(lora['hash'].lower()) lora['preview_url'] = self._lora_scanner.get_preview_url_by_hash(lora['hash'].lower())
lora['localPath'] = self._lora_scanner.get_lora_path_by_hash(lora['hash'].lower()) lora['localPath'] = self._lora_scanner.get_path_by_hash(lora['hash'].lower())
result = { result = {
'items': paginated_items, 'items': paginated_items,
@@ -655,9 +655,9 @@ class RecipeScanner:
for lora in formatted_recipe['loras']: for lora in formatted_recipe['loras']:
if 'hash' in lora and lora['hash']: if 'hash' in lora and lora['hash']:
lora_hash = lora['hash'].lower() lora_hash = lora['hash'].lower()
lora['inLibrary'] = self._lora_scanner.has_lora_hash(lora_hash) lora['inLibrary'] = self._lora_scanner.has_hash(lora_hash)
lora['preview_url'] = self._lora_scanner.get_preview_url_by_hash(lora_hash) lora['preview_url'] = self._lora_scanner.get_preview_url_by_hash(lora_hash)
lora['localPath'] = self._lora_scanner.get_lora_path_by_hash(lora_hash) lora['localPath'] = self._lora_scanner.get_path_by_hash(lora_hash)
return formatted_recipe return formatted_recipe