From fa48841645185c3cdda1b23ee55df6a1b4af6a4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Bachmann?= Date: Tue, 20 Jan 2026 07:16:48 +0000 Subject: [PATCH] 0.7.1 --- custom_components/bahmcloud_store/core.py | 25 +++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/custom_components/bahmcloud_store/core.py b/custom_components/bahmcloud_store/core.py index d1006bf..b50caff 100644 --- a/custom_components/bahmcloud_store/core.py +++ b/custom_components/bahmcloud_store/core.py @@ -808,13 +808,21 @@ class BCSCore: _LOGGER.debug("BCS ensure_repo_details failed for %s", repo_id, exc_info=True) return r - async def list_repo_versions(self, repo_id: str, *, limit: int = 20) -> list[dict[str, Any]]: + async def list_repo_versions( + self, + repo_id: str, + *, + limit: int = 20, + force_refresh: bool = False, + ) -> list[dict[str, Any]]: repo = self.get_repo(repo_id) if not repo: return [] # Prefer cached version lists to avoid hammering provider APIs (notably GitHub unauthenticated - # rate limits). We refresh on-demand when the user opens the selector. + # rate limits). However, if the cached list is clearly a degraded fallback (e.g. only + # "Latest" + "Branch"), we treat it as stale and retry immediately when the user requests + # versions again. cached = None cached_ts = 0 async with self._repo_cache_lock: @@ -823,8 +831,17 @@ class BCSCore: cached_ts = int(cached.get("versions_ts", 0) or 0) now = int(time.time()) - if isinstance(cached, dict) and cached.get("versions") and (now - cached_ts) < VERSIONS_CACHE_TTL_SECONDS: - return list(cached.get("versions") or []) + cached_versions = list(cached.get("versions") or []) if isinstance(cached, dict) else [] + cache_fresh = (now - cached_ts) < VERSIONS_CACHE_TTL_SECONDS + + # Cache hit if it's fresh and not degraded, unless the caller explicitly wants a refresh. + if ( + not force_refresh + and cached_versions + and cache_fresh + and len(cached_versions) > 2 + ): + return cached_versions try: versions = await fetch_repo_versions(