perf(registry): compute host-based dict
Python Lint CI / ruff-format-check (push) Successful in 1m11s
Python Lint CI / ruff (push) Successful in 1m11s
Python Lint CI / ty (push) Successful in 1m30s
Docker CI / docker-build (push) Successful in 2m31s
Python Test CI / coverage (push) Has been cancelled

This commit is contained in:
2026-06-02 23:51:37 +02:00
parent e0c8eb1724
commit 2040b709d3
+17 -4
View File
@@ -10,6 +10,7 @@ if typing.TYPE_CHECKING:
class Registry:
__slots__ = [
"_host_pages",
"data_dir",
"logger",
"pages",
@@ -26,6 +27,15 @@ class Registry:
self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)
self.pages: dict[str, Page] = {}
self.data_dir = DataDir(params.data_dir)
self._host_pages: dict[str, Page] | None = None
@property
def host_pages(self) -> dict[str, Page]:
if self._host_pages is None:
self._host_pages = {
p.host: p for p in self.pages.values() if p.host is not None
}
return self._host_pages
def load_pages(self) -> None:
self.pages = {}
@@ -34,7 +44,7 @@ class Registry:
self.mark_ready(path)
def get_hosts(self) -> list[str]:
return [p.host for p in self.pages.values() if p.host is not None]
return list(self.host_pages.keys())
def add(self, path: str) -> None:
host = self.data_dir.get_file(path, self.HOST_FILE)
@@ -50,6 +60,7 @@ class Registry:
spa=self.data_dir.get_file(path, self.SPA_FILE),
ready=False,
)
self._host_pages = None
self.logger.info("Updated %s", self.pages[path])
def set_host(self, path: str, host: str) -> None:
@@ -59,6 +70,7 @@ class Registry:
self.data_dir.set_file(path, self.HOST_FILE, host)
self.data_dir.remove_file(path, self.HOST_ONLY_FILE)
self.pages[path].host = host
self._host_pages = None
self.logger.debug("Updated %s", self.pages[path])
def set_host_only(self, path: str, host: str) -> None:
@@ -69,6 +81,7 @@ class Registry:
self.data_dir.remove_file(path, self.HOST_FILE)
self.pages[path].host = host
self.pages[path].host_only = True
self._host_pages = None
self.logger.debug("Updated %s", self.pages[path])
def set_token_hash(self, path: str, token_hash: str) -> None:
@@ -113,6 +126,7 @@ class Registry:
if path in self.pages:
page = self.pages[path]
del self.pages[path]
self._host_pages = None
self.logger.info("Removed %s", page)
return True
return False
@@ -123,7 +137,6 @@ class Registry:
return None
def get_from_host(self, host: str) -> Page | None:
for p in self.pages.values():
if p.host == host and p.ready:
return p
if host in self.host_pages and self.host_pages[host].ready:
return self.host_pages[host]
return None