From d78c2f785fcb4d1f050e00a0d53e0c1f7481e359 Mon Sep 17 00:00:00 2001 From: Vinta Chen Date: Sun, 22 Mar 2026 01:32:26 +0800 Subject: [PATCH] refactor(website): hoist loop-invariant variables outside the fetch loop now_iso and total_batches were recomputed on every iteration. Moving them above the loop makes intent clearer and avoids redundant work. Also simplifies cache dict construction with dict unpacking. Co-Authored-By: Claude --- website/fetch_github_stars.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/website/fetch_github_stars.py b/website/fetch_github_stars.py index c6398531..d3b024ed 100644 --- a/website/fetch_github_stars.py +++ b/website/fetch_github_stars.py @@ -136,6 +136,9 @@ def main() -> None: fetched_count = 0 skipped_repos: list[str] = [] + now_iso = now.isoformat() + total_batches = (len(to_fetch) + BATCH_SIZE - 1) // BATCH_SIZE + with httpx.Client( headers={"Authorization": f"bearer {token}", "Content-Type": "application/json"}, transport=httpx.HTTPTransport(retries=2), @@ -144,7 +147,6 @@ def main() -> None: for i in range(0, len(to_fetch), BATCH_SIZE): batch = to_fetch[i : i + BATCH_SIZE] batch_num = i // BATCH_SIZE + 1 - total_batches = (len(to_fetch) + BATCH_SIZE - 1) // BATCH_SIZE print(f"Fetching batch {batch_num}/{total_batches} ({len(batch)} repos)...") try: @@ -158,15 +160,9 @@ def main() -> None: save_cache(cache) sys.exit(1) - now_iso = now.isoformat() for repo in batch: if repo in results: - cache[repo] = { - "stars": results[repo]["stars"], - "owner": results[repo]["owner"], - "last_commit_at": results[repo]["last_commit_at"], - "fetched_at": now_iso, - } + cache[repo] = {**results[repo], "fetched_at": now_iso} fetched_count += 1 else: skipped_repos.append(repo)