Skip to content

Commit

Permalink
Frontend Manager: avoid redundant gh calls for static versions (#5152)
Browse files Browse the repository at this point in the history
* Frontend Manager: avoid redundant gh calls for static versions

* actually, removing old tmpdir isn't needed

I tested - downloader code handles this case well already
(also rmdir was wrong func anyway, needed shutil.rmtree if it had content)

* add code comment
  • Loading branch information
mcmonkey4eva authored Oct 16, 2024
1 parent 0dbba9f commit c695c4a
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions app/frontend_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ def init_frontend_unsafe(cls, version_string: str, provider: Optional[FrontEndPr
return cls.DEFAULT_FRONTEND_PATH

repo_owner, repo_name, version = cls.parse_version_string(version_string)

if version.startswith("v"):
expected_path = str(Path(cls.CUSTOM_FRONTENDS_ROOT) / f"{repo_owner}_{repo_name}" / version.lstrip("v"))
if os.path.exists(expected_path):
logging.info(f"Using existing copy of specific frontend version tag: {repo_owner}/{repo_name}@{version}")
return expected_path

logging.info(f"Initializing frontend: {repo_owner}/{repo_name}@{version}, requesting version details from GitHub...")

provider = provider or FrontEndProvider(repo_owner, repo_name)
release = provider.get_release(version)

Expand All @@ -159,16 +168,20 @@ def init_frontend_unsafe(cls, version_string: str, provider: Optional[FrontEndPr
Path(cls.CUSTOM_FRONTENDS_ROOT) / provider.folder_name / semantic_version
)
if not os.path.exists(web_root):
# Use tmp path until complete to avoid path exists check passing from interrupted downloads
tmp_path = web_root + ".tmp"
try:
os.makedirs(web_root, exist_ok=True)
os.makedirs(tmp_path, exist_ok=True)
logging.info(
"Downloading frontend(%s) version(%s) to (%s)",
provider.folder_name,
semantic_version,
web_root,
tmp_path,
)
logging.debug(release)
download_release_asset_zip(release, destination_path=web_root)
download_release_asset_zip(release, destination_path=tmp_path)
if os.listdir(tmp_path):
os.rename(tmp_path, web_root)
finally:
# Clean up the directory if it is empty, i.e. the download failed
if not os.listdir(web_root):
Expand Down

0 comments on commit c695c4a

Please sign in to comment.