Skip to content

Commit

Permalink
Added a cache in library_url
Browse files Browse the repository at this point in the history
  • Loading branch information
muffato committed Sep 7, 2022
1 parent 40e08a1 commit 417e737
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions shpc/main/registry/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __init__(self, source, tag=None, subdir=None):
self.url = "ssh://" + source
else:
self.url = "https://" + source

self._library_url = None
self.is_cloned = False

self.tag = tag
Expand All @@ -126,16 +126,21 @@ def library_url(self):
"""
Retrieve the web url, either pages or (eventually) custom.
"""
if self._library_url is not None:
return self._library_url
url = self.url
if url.endswith(".git"):
url = url[:-4]
parts = url.split("/")
domain = parts[2]
if domain in self.library_url_schemes:
return self.library_url_schemes[domain] % (
self._library_url = self.library_url_schemes[domain] % (
parts[3],
"/".join(parts[4:]),
)
else:
self._library_url = ""
return self._library_url

def exists(self, name):
"""
Expand Down Expand Up @@ -184,11 +189,10 @@ def _update_cache(self, force=False):
if self._cache and not force:
return

library_url = self.library_url
if library_url is None:
if not self.library_url:
return self._update_clone_cache()
# Check for exposed library API on GitHub or GitLab pages
response = requests.get(library_url)
response = requests.get(self.library_url)
if response.status_code != 200:
return self._update_clone_cache()
self._cache = response.json()
Expand Down

0 comments on commit 417e737

Please sign in to comment.