f
This commit is contained in:
@@ -222,19 +222,27 @@ class SharedArgs:
|
||||
if not force and hasattr(SharedArgs, "_cached_available_stores"):
|
||||
return SharedArgs._cached_available_stores or []
|
||||
|
||||
# Refresh the cache
|
||||
SharedArgs._refresh_store_choices_cache(config)
|
||||
# Refresh the cache. When not forcing, prefer a lightweight configured-name
|
||||
# pass to avoid instantiating backends (which may perform work such as opening DBs).
|
||||
if not force:
|
||||
SharedArgs._refresh_store_choices_cache(config, skip_instantiation=True)
|
||||
else:
|
||||
SharedArgs._refresh_store_choices_cache(config, skip_instantiation=False)
|
||||
return SharedArgs._cached_available_stores or []
|
||||
|
||||
@staticmethod
|
||||
def _refresh_store_choices_cache(config: Optional[Dict[str, Any]] = None) -> None:
|
||||
def _refresh_store_choices_cache(config: Optional[Dict[str, Any]] = None, skip_instantiation: bool = False) -> None:
|
||||
"""Refresh the cached store choices list. Should be called once at startup.
|
||||
|
||||
This performs the actual StoreRegistry initialization check and caches the result.
|
||||
Subsequent calls to get_store_choices() will use this cache.
|
||||
This performs a lightweight pass first (reads configured names only, without
|
||||
instantiating backend classes) to avoid side-effects during autocompletion or
|
||||
other quick lookups. When `skip_instantiation` is False, the function will
|
||||
attempt a full StoreRegistry initialization to filter out backends that failed
|
||||
to initialize properly.
|
||||
|
||||
Args:
|
||||
config: Config dict. If not provided, will try to load from config module.
|
||||
skip_instantiation: When True, do not instantiate backend classes; use a lightweight list only.
|
||||
"""
|
||||
try:
|
||||
if config is None:
|
||||
@@ -245,17 +253,27 @@ class SharedArgs:
|
||||
SharedArgs._cached_available_stores = []
|
||||
return
|
||||
|
||||
# Initialize registry once to filter disabled stores
|
||||
from Store.registry import Store as StoreRegistry
|
||||
|
||||
# Lightweight pass: return configured names without instantiating backends
|
||||
try:
|
||||
registry = StoreRegistry(config=config, suppress_debug=True)
|
||||
available = registry.list_backends()
|
||||
SharedArgs._cached_available_stores = available or []
|
||||
except Exception:
|
||||
# If registry creation fails, fallback to configured names
|
||||
from Store.registry import list_configured_backend_names
|
||||
SharedArgs._cached_available_stores = list_configured_backend_names(config) or []
|
||||
except Exception:
|
||||
SharedArgs._cached_available_stores = []
|
||||
|
||||
# If caller explicitly requested a full scan, instantiate registry to get
|
||||
# only backends that actually initialized successfully.
|
||||
if skip_instantiation:
|
||||
return
|
||||
|
||||
try:
|
||||
from Store.registry import Store as StoreRegistry
|
||||
registry = StoreRegistry(config=config, suppress_debug=True)
|
||||
available = registry.list_backends()
|
||||
if available:
|
||||
SharedArgs._cached_available_stores = available
|
||||
except Exception:
|
||||
# Keep the lightweight list if full initialization fails
|
||||
pass
|
||||
except Exception:
|
||||
SharedArgs._cached_available_stores = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user