Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9acbd5046c | |||
| 8d63c88e69 | |||
| cffb0af60e | |||
| 857b7a127a | |||
| 66b24ece48 | |||
| 0cc3b466e0 |
@@ -11,6 +11,13 @@ Sections:
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## [0.6.3] - 2026-01-18
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Improved Store performance for large indexes by avoiding full metadata enrichment during list refresh.
|
||||||
|
- Repository details are loaded on demand, reducing initial load time and network requests.
|
||||||
|
- Index refresh is skipped when the index content has not changed.
|
||||||
|
|
||||||
## [0.6.2] - 2026-01-18
|
## [0.6.2] - 2026-01-18
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ async def async_setup(hass: HomeAssistant, config: dict) -> bool:
|
|||||||
BCSApiView,
|
BCSApiView,
|
||||||
BCSReadmeView,
|
BCSReadmeView,
|
||||||
BCSVersionsView,
|
BCSVersionsView,
|
||||||
|
BCSRepoDetailView,
|
||||||
BCSCustomRepoView,
|
BCSCustomRepoView,
|
||||||
BCSInstallView,
|
BCSInstallView,
|
||||||
BCSUpdateView,
|
BCSUpdateView,
|
||||||
@@ -49,6 +50,7 @@ async def async_setup(hass: HomeAssistant, config: dict) -> bool:
|
|||||||
hass.http.register_view(BCSApiView(core))
|
hass.http.register_view(BCSApiView(core))
|
||||||
hass.http.register_view(BCSReadmeView(core))
|
hass.http.register_view(BCSReadmeView(core))
|
||||||
hass.http.register_view(BCSVersionsView(core))
|
hass.http.register_view(BCSVersionsView(core))
|
||||||
|
hass.http.register_view(BCSRepoDetailView(core))
|
||||||
hass.http.register_view(BCSCustomRepoView(core))
|
hass.http.register_view(BCSCustomRepoView(core))
|
||||||
hass.http.register_view(BCSInstallView(core))
|
hass.http.register_view(BCSInstallView(core))
|
||||||
hass.http.register_view(BCSUpdateView(core))
|
hass.http.register_view(BCSUpdateView(core))
|
||||||
@@ -62,7 +64,7 @@ async def async_setup(hass: HomeAssistant, config: dict) -> bool:
|
|||||||
frontend_url_path="bahmcloud-store",
|
frontend_url_path="bahmcloud-store",
|
||||||
webcomponent_name="bahmcloud-store-panel",
|
webcomponent_name="bahmcloud-store-panel",
|
||||||
# IMPORTANT: bump v to avoid caching old JS
|
# IMPORTANT: bump v to avoid caching old JS
|
||||||
module_url="/api/bahmcloud_store_static/panel.js?v=105",
|
module_url="/api/bahmcloud_store_static/panel.js?v=106",
|
||||||
sidebar_title="Bahmcloud Store",
|
sidebar_title="Bahmcloud Store",
|
||||||
sidebar_icon="mdi:store",
|
sidebar_icon="mdi:store",
|
||||||
require_admin=True,
|
require_admin=True,
|
||||||
|
|||||||
@@ -89,6 +89,9 @@ class BCSCore:
|
|||||||
self.last_index_hash: str | None = None
|
self.last_index_hash: str | None = None
|
||||||
self.last_index_loaded_at: float | None = None
|
self.last_index_loaded_at: float | None = None
|
||||||
|
|
||||||
|
# Fast refresh: skip expensive processing when index/custom repos unchanged
|
||||||
|
self._last_refresh_signature: str | None = None
|
||||||
|
|
||||||
self._install_lock = asyncio.Lock()
|
self._install_lock = asyncio.Lock()
|
||||||
self._installed_cache: dict[str, Any] = {}
|
self._installed_cache: dict[str, Any] = {}
|
||||||
|
|
||||||
@@ -178,6 +181,19 @@ class BCSCore:
|
|||||||
|
|
||||||
custom_repos = await self.storage.list_custom_repos()
|
custom_repos = await self.storage.list_custom_repos()
|
||||||
|
|
||||||
|
# Fast path: if index + custom repos did not change, skip expensive work.
|
||||||
|
try:
|
||||||
|
custom_sig = [(c.id, (c.url or '').strip(), (c.name or '').strip()) for c in (custom_repos or [])]
|
||||||
|
custom_sig.sort()
|
||||||
|
refresh_signature = json.dumps({"index_hash": self.last_index_hash, "custom": custom_sig}, sort_keys=True)
|
||||||
|
except Exception:
|
||||||
|
refresh_signature = f"{self.last_index_hash}:{len(custom_repos or [])}"
|
||||||
|
|
||||||
|
if self._last_refresh_signature and refresh_signature == self._last_refresh_signature and self.repos:
|
||||||
|
_LOGGER.debug("BCS refresh skipped (no changes detected)")
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
merged: dict[str, RepoItem] = {}
|
merged: dict[str, RepoItem] = {}
|
||||||
|
|
||||||
for item in index_repos:
|
for item in index_repos:
|
||||||
@@ -194,9 +210,11 @@ class BCSCore:
|
|||||||
for r in merged.values():
|
for r in merged.values():
|
||||||
r.provider = detect_provider(r.url)
|
r.provider = detect_provider(r.url)
|
||||||
|
|
||||||
await self._enrich_and_resolve(merged)
|
await self._enrich_installed_only(merged)
|
||||||
self.repos = merged
|
self.repos = merged
|
||||||
|
|
||||||
|
self._last_refresh_signature = refresh_signature
|
||||||
|
|
||||||
_LOGGER.info(
|
_LOGGER.info(
|
||||||
"BCS refresh complete: repos=%s (index=%s, custom=%s)",
|
"BCS refresh complete: repos=%s (index=%s, custom=%s)",
|
||||||
len(self.repos),
|
len(self.repos),
|
||||||
@@ -238,6 +256,87 @@ class BCSCore:
|
|||||||
|
|
||||||
await asyncio.gather(*(process_one(r) for r in merged.values()), return_exceptions=True)
|
await asyncio.gather(*(process_one(r) for r in merged.values()), return_exceptions=True)
|
||||||
|
|
||||||
|
|
||||||
|
async def _enrich_installed_only(self, merged: dict[str, RepoItem]) -> None:
|
||||||
|
"""Enrich only installed repos (fast refresh for large indexes).
|
||||||
|
|
||||||
|
This keeps the backend responsive even with thousands of repositories.
|
||||||
|
Details for non-installed repos are fetched on-demand.
|
||||||
|
"""
|
||||||
|
installed_map: dict[str, Any] = getattr(self, "_installed_cache", {}) or {}
|
||||||
|
if not isinstance(installed_map, dict) or not installed_map:
|
||||||
|
return
|
||||||
|
|
||||||
|
to_process: list[RepoItem] = []
|
||||||
|
for rid in installed_map.keys():
|
||||||
|
r = merged.get(str(rid))
|
||||||
|
if r:
|
||||||
|
to_process.append(r)
|
||||||
|
|
||||||
|
if not to_process:
|
||||||
|
return
|
||||||
|
|
||||||
|
sem = asyncio.Semaphore(6)
|
||||||
|
|
||||||
|
async def process_one(r: RepoItem) -> None:
|
||||||
|
async with sem:
|
||||||
|
await self._enrich_one_repo(r)
|
||||||
|
|
||||||
|
await asyncio.gather(*(process_one(r) for r in to_process), return_exceptions=True)
|
||||||
|
|
||||||
|
async def _enrich_one_repo(self, r: RepoItem) -> None:
|
||||||
|
"""Fetch provider info + metadata for a single repo item."""
|
||||||
|
info: RepoInfo = await fetch_repo_info(self.hass, r.url)
|
||||||
|
|
||||||
|
r.provider = info.provider or r.provider
|
||||||
|
r.owner = info.owner or r.owner
|
||||||
|
r.provider_repo_name = info.repo_name
|
||||||
|
r.provider_description = info.description
|
||||||
|
r.default_branch = info.default_branch or r.default_branch
|
||||||
|
|
||||||
|
r.latest_version = info.latest_version
|
||||||
|
r.latest_version_source = info.latest_version_source
|
||||||
|
|
||||||
|
md: RepoMetadata = await fetch_repo_metadata(self.hass, r.url, r.default_branch)
|
||||||
|
r.meta_source = md.source
|
||||||
|
if md.name:
|
||||||
|
r.meta_name = md.name
|
||||||
|
r.name = md.name
|
||||||
|
r.meta_description = md.description
|
||||||
|
if md.category:
|
||||||
|
r.meta_category = md.category
|
||||||
|
r.meta_author = md.author
|
||||||
|
r.meta_maintainer = md.maintainer
|
||||||
|
|
||||||
|
# Keep a stable name fallback
|
||||||
|
if not r.name:
|
||||||
|
r.name = r.provider_repo_name or r.url
|
||||||
|
|
||||||
|
async def ensure_repo_details(self, repo_id: str) -> RepoItem | None:
|
||||||
|
"""Ensure provider/meta/latest fields are loaded for a repo.
|
||||||
|
|
||||||
|
Used by the UI when a repo detail view is opened.
|
||||||
|
"""
|
||||||
|
r = self.get_repo(repo_id)
|
||||||
|
if not r:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# If we already have a latest_version (or provider_description), consider it enriched.
|
||||||
|
if r.latest_version or r.provider_description or r.meta_source:
|
||||||
|
return r
|
||||||
|
|
||||||
|
try:
|
||||||
|
await self._enrich_one_repo(r)
|
||||||
|
except Exception:
|
||||||
|
_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) -> list[dict[str, Any]]:
|
||||||
|
repo = self.get_repo(repo_id)
|
||||||
|
if not repo:
|
||||||
|
return []
|
||||||
|
return await fetch_repo_versions(self.hass, repo.url)
|
||||||
|
|
||||||
def _add_cache_buster(self, url: str) -> str:
|
def _add_cache_buster(self, url: str) -> str:
|
||||||
parts = urlsplit(url)
|
parts = urlsplit(url)
|
||||||
q = dict(parse_qsl(parts.query, keep_blank_values=True))
|
q = dict(parse_qsl(parts.query, keep_blank_values=True))
|
||||||
@@ -329,6 +428,7 @@ class BCSCore:
|
|||||||
name=name,
|
name=name,
|
||||||
url=repo_url,
|
url=repo_url,
|
||||||
source="index",
|
source="index",
|
||||||
|
meta_category=str(r.get("category")) if r.get("category") else None,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"domain": "bahmcloud_store",
|
"domain": "bahmcloud_store",
|
||||||
"name": "Bahmcloud Store",
|
"name": "Bahmcloud Store",
|
||||||
"version": "0.6.2",
|
"version": "0.6.3",
|
||||||
"documentation": "https://git.bahmcloud.de/bahmcloud/bahmcloud_store",
|
"documentation": "https://git.bahmcloud.de/bahmcloud/bahmcloud_store",
|
||||||
"platforms": ["update"],
|
"platforms": ["update"],
|
||||||
"requirements": [],
|
"requirements": [],
|
||||||
|
|||||||
@@ -389,10 +389,29 @@ class BahmcloudStorePanel extends HTMLElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._update();
|
this._update();
|
||||||
|
this._loadRepoDetails(repoId);
|
||||||
this._loadReadme(repoId);
|
this._loadReadme(repoId);
|
||||||
this._loadVersions(repoId);
|
this._loadVersions(repoId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async _loadRepoDetails(repoId) {
|
||||||
|
if (!this._hass || !repoId) return;
|
||||||
|
try {
|
||||||
|
const resp = await this._hass.callApi("get", `bcs/repo?repo_id=${encodeURIComponent(repoId)}`);
|
||||||
|
if (resp?.ok && resp.repo) {
|
||||||
|
this._detailRepo = resp.repo;
|
||||||
|
// Also update the cached list item if present
|
||||||
|
const repos = Array.isArray(this._data?.repos) ? this._data.repos : [];
|
||||||
|
const idx = repos.findIndex((r) => this._safeId(r?.id) === repoId);
|
||||||
|
if (idx >= 0) repos[idx] = resp.repo;
|
||||||
|
this._update();
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// ignore: details are optional
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async _loadVersions(repoId) {
|
async _loadVersions(repoId) {
|
||||||
if (!this._hass) return;
|
if (!this._hass) return;
|
||||||
if (!repoId) return;
|
if (!repoId) return;
|
||||||
|
|||||||
@@ -442,3 +442,55 @@ class BCSRestartView(HomeAssistantView):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
_LOGGER.exception("BCS restart failed: %s", e)
|
_LOGGER.exception("BCS restart failed: %s", e)
|
||||||
return web.json_response({"ok": False, "message": str(e) or "Restart failed"}, status=500)
|
return web.json_response({"ok": False, "message": str(e) or "Restart failed"}, status=500)
|
||||||
|
|
||||||
|
class BCSRepoDetailView(HomeAssistantView):
|
||||||
|
url = "/api/bcs/repo"
|
||||||
|
name = "api:bcs_repo"
|
||||||
|
requires_auth = True
|
||||||
|
|
||||||
|
def __init__(self, core: Any) -> None:
|
||||||
|
self.core: BCSCore = core
|
||||||
|
|
||||||
|
async def get(self, request: web.Request) -> web.Response:
|
||||||
|
repo_id = (request.query.get("repo_id") or "").strip()
|
||||||
|
if not repo_id:
|
||||||
|
return web.json_response({"ok": False, "message": "Missing repo_id"}, status=400)
|
||||||
|
|
||||||
|
try:
|
||||||
|
repo = await self.core.ensure_repo_details(repo_id)
|
||||||
|
if not repo:
|
||||||
|
return web.json_response({"ok": False, "message": "Repo not found"}, status=404)
|
||||||
|
|
||||||
|
inst = self.core.get_installed(repo_id) or {}
|
||||||
|
installed = bool(inst)
|
||||||
|
domains = inst.get("domains") or []
|
||||||
|
if not isinstance(domains, list):
|
||||||
|
domains = []
|
||||||
|
|
||||||
|
return web.json_response({
|
||||||
|
"ok": True,
|
||||||
|
"repo": {
|
||||||
|
"id": repo.id,
|
||||||
|
"name": repo.name,
|
||||||
|
"url": repo.url,
|
||||||
|
"source": repo.source,
|
||||||
|
"owner": repo.owner,
|
||||||
|
"provider": repo.provider,
|
||||||
|
"repo_name": repo.provider_repo_name,
|
||||||
|
"description": repo.provider_description or repo.meta_description,
|
||||||
|
"default_branch": repo.default_branch,
|
||||||
|
"latest_version": repo.latest_version,
|
||||||
|
"latest_version_source": repo.latest_version_source,
|
||||||
|
"category": repo.meta_category,
|
||||||
|
"meta_author": repo.meta_author,
|
||||||
|
"meta_maintainer": repo.meta_maintainer,
|
||||||
|
"meta_source": repo.meta_source,
|
||||||
|
"installed": installed,
|
||||||
|
"installed_version": inst.get("installed_version"),
|
||||||
|
"installed_manifest_version": inst.get("installed_manifest_version"),
|
||||||
|
"installed_domains": domains,
|
||||||
|
}
|
||||||
|
}, status=200)
|
||||||
|
except Exception as e:
|
||||||
|
_LOGGER.exception("BCS repo details failed: %s", e)
|
||||||
|
return web.json_response({"ok": False, "message": str(e) or "Repo details failed"}, status=500)
|
||||||
|
|||||||
Reference in New Issue
Block a user