refactor: consolidate load_cache into build.load_stars

load_cache was a duplicate of logic now living in build.load_stars.
Switch the call site to the shared helper and remove the redundant
local function and its tests.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Vinta Chen
2026-03-18 17:28:53 +08:00
parent 143abbf201
commit af3baab2ed
2 changed files with 2 additions and 35 deletions

View File

@@ -10,7 +10,7 @@ from pathlib import Path
import httpx
from build import extract_github_repo
from build import extract_github_repo, load_stars
CACHE_MAX_AGE_DAYS = 7
DATA_DIR = Path(__file__).parent / "data"
@@ -30,17 +30,6 @@ def extract_github_repos(text: str) -> set[str]:
return repos
def load_cache() -> dict:
"""Load the star cache from disk. Returns empty dict if missing or corrupt."""
if CACHE_FILE.exists():
try:
return json.loads(CACHE_FILE.read_text(encoding="utf-8"))
except json.JSONDecodeError:
print(f"Warning: corrupt cache at {CACHE_FILE}, starting fresh.", file=sys.stderr)
return {}
return {}
def save_cache(cache: dict) -> None:
"""Write the star cache to disk, creating data/ dir if needed."""
DATA_DIR.mkdir(parents=True, exist_ok=True)
@@ -114,7 +103,7 @@ def main() -> None:
current_repos = extract_github_repos(readme_text)
print(f"Found {len(current_repos)} GitHub repos in README.md")
cache = load_cache()
cache = load_stars(CACHE_FILE)
now = datetime.now(timezone.utc)
# Prune entries not in current README