Enhance LoraRoutes and templates for improved cache initialization handling

- Updated LoraRoutes to better check cache initialization status and handle loading states.
- Added logging for successful cache loading and error handling for cache retrieval failures.
- Enhanced base.html and loras.html templates to display a loading spinner and initialization notice during cache setup.
- Improved user experience by ensuring the loading notice is displayed appropriately based on initialization state.
This commit is contained in:
Will Miao
2025-03-28 15:04:35 +08:00
parent 85c3e33343
commit 5a8a402fdc
4 changed files with 91 additions and 26 deletions

View File

@@ -3,6 +3,7 @@ import os
import logging
import asyncio
import shutil
import time
from typing import List, Dict, Optional
from dataclasses import dataclass
from operator import itemgetter
@@ -91,6 +92,7 @@ class LoraScanner:
async def _initialize_cache(self) -> None:
"""Initialize or refresh the cache"""
try:
start_time = time.time()
# Clear existing hash index
self._hash_index.clear()
@@ -122,7 +124,7 @@ class LoraScanner:
await self._cache.resort()
self._initialization_task = None
logger.info("LoRA Manager: Cache initialization completed")
logger.info(f"LoRA Manager: Cache initialization completed in {time.time() - start_time:.2f} seconds, found {len(raw_data)} loras")
except Exception as e:
logger.error(f"LoRA Manager: Error initializing cache: {e}")
self._cache = LoraCache(