From afb012029fcd4088734735f4b217dbc6eb31bcc9 Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Thu, 29 May 2025 08:50:17 +0800 Subject: [PATCH] Enhance get_cached_data method: improve cache rebuilding logic and ensure cache is saved after initialization --- py/services/model_scanner.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/py/services/model_scanner.py b/py/services/model_scanner.py index 4ed69176..7acd0f72 100644 --- a/py/services/model_scanner.py +++ b/py/services/model_scanner.py @@ -475,17 +475,23 @@ class ModelScanner: # If force refresh is requested, initialize the cache directly if force_refresh: # If rebuild_cache is True, try to reload from disk before reconciliation - if rebuild_cache and self._cache is not None: + if rebuild_cache: logger.info(f"{self.model_type.capitalize()} Scanner: Attempting to rebuild cache from disk...") cache_loaded = await self._load_cache_from_disk() if cache_loaded: logger.info(f"{self.model_type.capitalize()} Scanner: Successfully reloaded cache from disk") else: - logger.info(f"{self.model_type.capitalize()} Scanner: Could not reload cache from disk, proceeding with normal refresh") - + logger.info(f"{self.model_type.capitalize()} Scanner: Could not reload cache from disk, proceeding with complete rebuild") + # If loading from disk failed, do a complete rebuild and save to disk + await self._initialize_cache() + await self._save_cache_to_disk() + return self._cache + if self._cache is None: # For initial creation, do a full initialization await self._initialize_cache() + # Save the newly built cache + await self._save_cache_to_disk() else: # For subsequent refreshes, use fast reconciliation await self._reconcile_cache()