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
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:
+17
-4
@@ -10,6 +10,7 @@ if typing.TYPE_CHECKING:
|
|||||||
|
|
||||||
class Registry:
|
class Registry:
|
||||||
__slots__ = [
|
__slots__ = [
|
||||||
|
"_host_pages",
|
||||||
"data_dir",
|
"data_dir",
|
||||||
"logger",
|
"logger",
|
||||||
"pages",
|
"pages",
|
||||||
@@ -26,6 +27,15 @@ class Registry:
|
|||||||
self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)
|
self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)
|
||||||
self.pages: dict[str, Page] = {}
|
self.pages: dict[str, Page] = {}
|
||||||
self.data_dir = DataDir(params.data_dir)
|
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:
|
def load_pages(self) -> None:
|
||||||
self.pages = {}
|
self.pages = {}
|
||||||
@@ -34,7 +44,7 @@ class Registry:
|
|||||||
self.mark_ready(path)
|
self.mark_ready(path)
|
||||||
|
|
||||||
def get_hosts(self) -> list[str]:
|
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:
|
def add(self, path: str) -> None:
|
||||||
host = self.data_dir.get_file(path, self.HOST_FILE)
|
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),
|
spa=self.data_dir.get_file(path, self.SPA_FILE),
|
||||||
ready=False,
|
ready=False,
|
||||||
)
|
)
|
||||||
|
self._host_pages = None
|
||||||
self.logger.info("Updated %s", self.pages[path])
|
self.logger.info("Updated %s", self.pages[path])
|
||||||
|
|
||||||
def set_host(self, path: str, host: str) -> None:
|
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.set_file(path, self.HOST_FILE, host)
|
||||||
self.data_dir.remove_file(path, self.HOST_ONLY_FILE)
|
self.data_dir.remove_file(path, self.HOST_ONLY_FILE)
|
||||||
self.pages[path].host = host
|
self.pages[path].host = host
|
||||||
|
self._host_pages = None
|
||||||
self.logger.debug("Updated %s", self.pages[path])
|
self.logger.debug("Updated %s", self.pages[path])
|
||||||
|
|
||||||
def set_host_only(self, path: str, host: str) -> None:
|
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.data_dir.remove_file(path, self.HOST_FILE)
|
||||||
self.pages[path].host = host
|
self.pages[path].host = host
|
||||||
self.pages[path].host_only = True
|
self.pages[path].host_only = True
|
||||||
|
self._host_pages = None
|
||||||
self.logger.debug("Updated %s", self.pages[path])
|
self.logger.debug("Updated %s", self.pages[path])
|
||||||
|
|
||||||
def set_token_hash(self, path: str, token_hash: str) -> None:
|
def set_token_hash(self, path: str, token_hash: str) -> None:
|
||||||
@@ -113,6 +126,7 @@ class Registry:
|
|||||||
if path in self.pages:
|
if path in self.pages:
|
||||||
page = self.pages[path]
|
page = self.pages[path]
|
||||||
del self.pages[path]
|
del self.pages[path]
|
||||||
|
self._host_pages = None
|
||||||
self.logger.info("Removed %s", page)
|
self.logger.info("Removed %s", page)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
@@ -123,7 +137,6 @@ class Registry:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def get_from_host(self, host: str) -> Page | None:
|
def get_from_host(self, host: str) -> Page | None:
|
||||||
for p in self.pages.values():
|
if host in self.host_pages and self.host_pages[host].ready:
|
||||||
if p.host == host and p.ready:
|
return self.host_pages[host]
|
||||||
return p
|
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user