mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-24 22:52:12 -03:00
refactor(model-type): complete phase 5 cleanup by removing deprecated model_type field
- Remove backward compatibility code for `model_type` in `ModelScanner._build_cache_entry()` - Update `CheckpointScanner` to only handle `sub_type` in `adjust_metadata()` and `adjust_cached_entry()` - Delete deprecated aliases `resolve_civitai_model_type` and `normalize_civitai_model_type` from `model_query.py` - Update frontend components (`RecipeModal.js`, `ModelCard.js`, etc.) to use `sub_type` instead of `model_type` - Update API response format to return only `sub_type`, removing `model_type` from service responses - Revise technical documentation to mark Phase 5 as completed and remove outdated TODO items All cleanup tasks for the model type refactoring are now complete, ensuring consistent use of `sub_type` across the codebase.
This commit is contained in:
@@ -36,16 +36,9 @@ class CheckpointScanner(ModelScanner):
|
||||
|
||||
def adjust_metadata(self, metadata, file_path, root_path):
|
||||
"""Adjust metadata during scanning to set sub_type."""
|
||||
# Support both old 'model_type' and new 'sub_type' for backward compatibility
|
||||
if hasattr(metadata, "sub_type"):
|
||||
sub_type = self._resolve_sub_type(root_path)
|
||||
if sub_type:
|
||||
metadata.sub_type = sub_type
|
||||
elif hasattr(metadata, "model_type"):
|
||||
# Backward compatibility: fallback to model_type if sub_type not available
|
||||
sub_type = self._resolve_sub_type(root_path)
|
||||
if sub_type:
|
||||
metadata.model_type = sub_type
|
||||
sub_type = self._resolve_sub_type(root_path)
|
||||
if sub_type:
|
||||
metadata.sub_type = sub_type
|
||||
return metadata
|
||||
|
||||
def adjust_cached_entry(self, entry: Dict[str, Any]) -> Dict[str, Any]:
|
||||
@@ -55,8 +48,6 @@ class CheckpointScanner(ModelScanner):
|
||||
)
|
||||
if sub_type:
|
||||
entry["sub_type"] = sub_type
|
||||
# Also set model_type for backward compatibility during transition
|
||||
entry["model_type"] = sub_type
|
||||
return entry
|
||||
|
||||
def get_model_roots(self) -> List[str]:
|
||||
|
||||
@@ -22,8 +22,8 @@ class CheckpointService(BaseModelService):
|
||||
|
||||
async def format_response(self, checkpoint_data: Dict) -> Dict:
|
||||
"""Format Checkpoint data for API response"""
|
||||
# Get sub_type from cache entry (new field) or fallback to model_type (old field)
|
||||
sub_type = checkpoint_data.get("sub_type") or checkpoint_data.get("model_type", "checkpoint")
|
||||
# Get sub_type from cache entry (new canonical field)
|
||||
sub_type = checkpoint_data.get("sub_type", "checkpoint")
|
||||
|
||||
return {
|
||||
"model_name": checkpoint_data["model_name"],
|
||||
@@ -40,8 +40,7 @@ class CheckpointService(BaseModelService):
|
||||
"from_civitai": checkpoint_data.get("from_civitai", True),
|
||||
"usage_count": checkpoint_data.get("usage_count", 0),
|
||||
"notes": checkpoint_data.get("notes", ""),
|
||||
"sub_type": sub_type, # New canonical field
|
||||
"model_type": sub_type, # Backward compatibility
|
||||
"sub_type": sub_type,
|
||||
"favorite": checkpoint_data.get("favorite", False),
|
||||
"update_available": bool(checkpoint_data.get("update_available", False)),
|
||||
"civitai": self.filter_civitai_data(checkpoint_data.get("civitai", {}), minimal=True)
|
||||
|
||||
@@ -22,8 +22,8 @@ class EmbeddingService(BaseModelService):
|
||||
|
||||
async def format_response(self, embedding_data: Dict) -> Dict:
|
||||
"""Format Embedding data for API response"""
|
||||
# Get sub_type from cache entry (new field) or fallback to model_type (old field)
|
||||
sub_type = embedding_data.get("sub_type") or embedding_data.get("model_type", "embedding")
|
||||
# Get sub_type from cache entry (new canonical field)
|
||||
sub_type = embedding_data.get("sub_type", "embedding")
|
||||
|
||||
return {
|
||||
"model_name": embedding_data["model_name"],
|
||||
@@ -40,8 +40,7 @@ class EmbeddingService(BaseModelService):
|
||||
"from_civitai": embedding_data.get("from_civitai", True),
|
||||
# "usage_count": embedding_data.get("usage_count", 0), # TODO: Enable when embedding usage tracking is implemented
|
||||
"notes": embedding_data.get("notes", ""),
|
||||
"sub_type": sub_type, # New canonical field
|
||||
"model_type": sub_type, # Backward compatibility
|
||||
"sub_type": sub_type,
|
||||
"favorite": embedding_data.get("favorite", False),
|
||||
"update_available": bool(embedding_data.get("update_available", False)),
|
||||
"civitai": self.filter_civitai_data(embedding_data.get("civitai", {}), minimal=True)
|
||||
|
||||
@@ -3,6 +3,7 @@ import logging
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
from .base_model_service import BaseModelService
|
||||
from .model_query import resolve_sub_type
|
||||
from ..utils.models import LoraMetadata
|
||||
from ..config import config
|
||||
|
||||
@@ -23,8 +24,9 @@ class LoraService(BaseModelService):
|
||||
|
||||
async def format_response(self, lora_data: Dict) -> Dict:
|
||||
"""Format LoRA data for API response"""
|
||||
# Get sub_type from cache entry (new field) or fallback to model_type (old field)
|
||||
sub_type = lora_data.get("sub_type") or lora_data.get("model_type", "lora")
|
||||
# Resolve sub_type using priority: sub_type > model_type > civitai.model.type > default
|
||||
# Normalize to lowercase for consistent API responses
|
||||
sub_type = resolve_sub_type(lora_data).lower()
|
||||
|
||||
return {
|
||||
"model_name": lora_data["model_name"],
|
||||
@@ -46,8 +48,7 @@ class LoraService(BaseModelService):
|
||||
"notes": lora_data.get("notes", ""),
|
||||
"favorite": lora_data.get("favorite", False),
|
||||
"update_available": bool(lora_data.get("update_available", False)),
|
||||
"sub_type": sub_type, # New canonical field
|
||||
"model_type": sub_type, # Backward compatibility
|
||||
"sub_type": sub_type,
|
||||
"civitai": self.filter_civitai_data(
|
||||
lora_data.get("civitai", {}), minimal=True
|
||||
),
|
||||
|
||||
@@ -39,10 +39,6 @@ def normalize_sub_type(value: Any) -> Optional[str]:
|
||||
return candidate.lower() if candidate else None
|
||||
|
||||
|
||||
# Backward compatibility alias
|
||||
normalize_civitai_model_type = normalize_sub_type
|
||||
|
||||
|
||||
def resolve_sub_type(entry: Mapping[str, Any]) -> str:
|
||||
"""Extract the sub-type from metadata, checking multiple sources.
|
||||
|
||||
@@ -77,10 +73,6 @@ def resolve_sub_type(entry: Mapping[str, Any]) -> str:
|
||||
return DEFAULT_CIVITAI_MODEL_TYPE
|
||||
|
||||
|
||||
# Backward compatibility alias
|
||||
resolve_civitai_model_type = resolve_sub_type
|
||||
|
||||
|
||||
class SettingsProvider(Protocol):
|
||||
"""Protocol describing the SettingsManager contract used by query helpers."""
|
||||
|
||||
|
||||
@@ -275,16 +275,10 @@ class ModelScanner:
|
||||
_, license_flags = resolve_license_info(license_source or {})
|
||||
entry['license_flags'] = license_flags
|
||||
|
||||
# Handle sub_type (new canonical field) and model_type (backward compatibility)
|
||||
# Handle sub_type (new canonical field)
|
||||
sub_type = get_value('sub_type', None)
|
||||
model_type = get_value('model_type', None)
|
||||
|
||||
# Prefer sub_type, fallback to model_type for backward compatibility
|
||||
effective_sub_type = sub_type or model_type
|
||||
if effective_sub_type:
|
||||
entry['sub_type'] = effective_sub_type
|
||||
# Also keep model_type for backward compatibility during transition
|
||||
entry['model_type'] = effective_sub_type
|
||||
if sub_type:
|
||||
entry['sub_type'] = sub_type
|
||||
|
||||
return entry
|
||||
|
||||
|
||||
Reference in New Issue
Block a user