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

Adjust plugin filename scan for better performance #3514

Merged
merged 6 commits into from
May 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 14 additions & 12 deletions custom_components/hacs/repositories/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ async def get_package_content(self):

def update_filenames(self) -> None:
"""Get the filename to target."""
# Handler for plug requirement 3
if self.repository_manifest.filename:
valid_filenames = (self.repository_manifest.filename,)
content_in_root = self.repository_manifest.content_in_root
if specific_filename := self.repository_manifest.filename:
valid_filenames = (specific_filename,)
else:
valid_filenames = (
f"{self.data.name.replace('lovelace-', '')}.js",
Expand All @@ -110,7 +110,7 @@ def update_filenames(self) -> None:
f"{self.data.name}-bundle.js",
)

if not self.repository_manifest.content_in_root:
if not content_in_root:
if self.releases.objects:
release = self.releases.objects[0]
if release.assets:
Expand All @@ -124,11 +124,13 @@ def update_filenames(self) -> None:
self.content.path.remote = "release"
return

for location in ("",) if self.repository_manifest.content_in_root else ("dist", ""):
for filename in valid_filenames:
if f"{location+'/' if location else ''}{filename}" in [
x.full_path for x in self.tree
]:
self.data.file_name = filename.split("/")[-1]
self.content.path.remote = location
break
all_paths = {x.full_path for x in self.tree}
for filename in valid_filenames:
if filename in all_paths:
self.data.file_name = filename
self.content.path.remote = ""
return
if not content_in_root and f"dist/{filename}" in all_paths:
self.data.file_name = filename.split("/")[-1]
self.content.path.remote = "dist"
return