0.7.1
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user