Skip to content

Commit

Permalink
speed up url_to_repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaiyu Yang committed Nov 29, 2023
1 parent c4cb4ab commit 20e7063
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/lean_dojo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,19 @@ def normalize_url(url: str) -> str:
return _URL_REGEX.fullmatch(url)["url"] # Remove trailing `/`.


URL_TO_REPO_CACHE = {}


def url_to_repo(url: str, num_retries: int = 1) -> Repository:
url = normalize_url(url)
if url in URL_TO_REPO_CACHE:
return URL_TO_REPO_CACHE[url]

while True:
try:
return GITHUB.get_repo("/".join(url.split("/")[-2:]))
repo = GITHUB.get_repo("/".join(url.split("/")[-2:]))
URL_TO_REPO_CACHE[url] = repo
return repo
except Exception as ex:
if num_retries <= 0:
raise ex
Expand Down

0 comments on commit 20e7063

Please sign in to comment.