Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache stat of addon assets #4675

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions supervisor/addons/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ async def update(self) -> asyncio.Task | None:

try:
_LOGGER.info("Add-on '%s' successfully updated", self.slug)
self._clear_cache()
self.sys_addons.data.update(store)

# Cleanup
Expand Down Expand Up @@ -765,6 +766,7 @@ async def rebuild(self) -> asyncio.Task | None:
except DockerError as err:
raise AddonsError() from err

self._clear_cache()
self.sys_addons.data.update(self.addon_store)
_LOGGER.info("Add-on '%s' successfully rebuilt", self.slug)

Expand Down
27 changes: 23 additions & 4 deletions supervisor/addons/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ def __init__(self, coresys: CoreSys, slug: str):
coresys, JOB_GROUP_ADDON.format_map(defaultdict(str, slug=slug)), slug
)
self.slug: str = slug
self._path_icon_exists: bool | None = None
self._path_logo_exists: bool | None = None
self._path_changelog_exists: bool | None = None
self._path_documentation_exists: bool | None = None

def _clear_cache(self) -> None:
"""Clear cache."""
self._path_icon_exists = None
self._path_logo_exists = None
self._path_changelog_exists = None
self._path_documentation_exists = None

@property
@abstractmethod
Expand Down Expand Up @@ -491,22 +502,30 @@ def url(self) -> str | None:
@property
def with_icon(self) -> bool:
"""Return True if an icon exists."""
return self.path_icon.exists()
if self._path_icon_exists is None:
self._path_icon_exists = self.path_icon.exists()
return self._path_icon_exists

@property
def with_logo(self) -> bool:
"""Return True if a logo exists."""
return self.path_logo.exists()
if self._path_logo_exists is None:
self._path_logo_exists = self.path_logo.exists()
return self._path_logo_exists

@property
def with_changelog(self) -> bool:
"""Return True if a changelog exists."""
return self.path_changelog.exists()
if self._path_changelog_exists is None:
self._path_changelog_exists = self.path_changelog.exists()
return self._path_changelog_exists

@property
def with_documentation(self) -> bool:
"""Return True if a documentation exists."""
return self.path_documentation.exists()
if self._path_documentation_exists is None:
self._path_documentation_exists = self.path_documentation.exists()
return self._path_documentation_exists

@property
def supported_arch(self) -> list[str]:
Expand Down