Skip to content

Commit d7bb5ed

Browse files
vdberghppigazzini
authored andcommitted
Cache the result of normalize_repo for 10 minutes.
1 parent 378170c commit d7bb5ed

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

server/fishtest/github_api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
TIMEOUT = 3
2323
INITIAL_RATELIMIT = 5000
2424
LRU_CACHE_SIZE = 6000
25+
NORMALIZE_REPO_CACHE_SIZE = 128
26+
NORMALIZE_REPO_CACHE_EXPIRY_SECONDS = 600
2527

2628
_api_initialized = False
2729

@@ -379,7 +381,15 @@ def get_master_repo(
379381
r = r["parent"]
380382

381383

384+
normalize_repo_cache = LRUCache(NORMALIZE_REPO_CACHE_SIZE)
385+
386+
382387
def normalize_repo(repo):
388+
global normalize_repo_cache
389+
if repo in normalize_repo_cache:
390+
cache = normalize_repo_cache[repo]
391+
if time.time() - cache[0] < NORMALIZE_REPO_CACHE_EXPIRY_SECONDS:
392+
return cache[1]
383393
r = call(
384394
repo,
385395
_method="HEAD",
@@ -388,6 +398,7 @@ def normalize_repo(repo):
388398
_ignore_rate_limit=True,
389399
)
390400
r.raise_for_status()
401+
normalize_repo_cache[repo] = (time.time(), r.url)
391402
return r.url
392403

393404

server/fishtest/views.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,11 @@ def allow_github_api_calls():
17271727
return False
17281728
return True
17291729

1730-
user, repo = gh.parse_repo(gh.normalize_repo(tests_repo(run)))
1730+
try:
1731+
user, repo = gh.parse_repo(gh.normalize_repo(tests_repo(run)))
1732+
except Exception as e:
1733+
user, repo = gh.parse_repo(tests_repo(run))
1734+
print(f"Unable to normalize_repo: {str(e)}")
17311735

17321736
anchor_url = gh.compare_branches_url(
17331737
user1="official-stockfish",

0 commit comments

Comments
 (0)