Skip to content

Commit 417e737

Browse files
committed
Added a cache in library_url
1 parent 40e08a1 commit 417e737

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

shpc/main/registry/remote.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __init__(self, source, tag=None, subdir=None):
106106
self.url = "ssh://" + source
107107
else:
108108
self.url = "https://" + source
109-
109+
self._library_url = None
110110
self.is_cloned = False
111111

112112
self.tag = tag
@@ -126,16 +126,21 @@ def library_url(self):
126126
"""
127127
Retrieve the web url, either pages or (eventually) custom.
128128
"""
129+
if self._library_url is not None:
130+
return self._library_url
129131
url = self.url
130132
if url.endswith(".git"):
131133
url = url[:-4]
132134
parts = url.split("/")
133135
domain = parts[2]
134136
if domain in self.library_url_schemes:
135-
return self.library_url_schemes[domain] % (
137+
self._library_url = self.library_url_schemes[domain] % (
136138
parts[3],
137139
"/".join(parts[4:]),
138140
)
141+
else:
142+
self._library_url = ""
143+
return self._library_url
139144

140145
def exists(self, name):
141146
"""
@@ -184,11 +189,10 @@ def _update_cache(self, force=False):
184189
if self._cache and not force:
185190
return
186191

187-
library_url = self.library_url
188-
if library_url is None:
192+
if not self.library_url:
189193
return self._update_clone_cache()
190194
# Check for exposed library API on GitHub or GitLab pages
191-
response = requests.get(library_url)
195+
response = requests.get(self.library_url)
192196
if response.status_code != 200:
193197
return self._update_clone_cache()
194198
self._cache = response.json()

0 commit comments

Comments
 (0)