Skip to content

Commit

Permalink
Added a cache in library_url
Browse files Browse the repository at this point in the history
None is a valid value, so to distinguish between it and "_library_url hasn't
been computed yet", I check the attribute's presence.
  • Loading branch information
muffato committed Sep 7, 2022
1 parent 40e08a1 commit ec22dbe
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions shpc/main/registry/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,21 @@ def library_url(self):
"""
Retrieve the web url, either pages or (eventually) custom.
"""
if hasattr(self, "_library_url"): # Cannot do "if self._library_url" because None is a valid value
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 = None
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 self.library_url is None:
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 ec22dbe

Please sign in to comment.