refactor: replace manual total_seconds()/3600 with timedelta comparison

Use timedelta(hours=CACHE_MAX_AGE_HOURS) so the cache-age check
reads at the intended hours unit directly, removing the conversion
arithmetic.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Vinta Chen
2026-04-19 22:02:14 +08:00
parent 95115f7949
commit 6ae7c89688

View File

@@ -6,7 +6,7 @@ import os
import re
import sys
from collections.abc import Sequence
from datetime import UTC, datetime
from datetime import UTC, datetime, timedelta
from itertools import batched
from pathlib import Path
@@ -119,13 +119,13 @@ def main() -> None:
cache = pruned
# Determine which repos need fetching (missing or stale)
max_age = timedelta(hours=CACHE_MAX_AGE_HOURS)
to_fetch = []
for repo in sorted(current_repos):
entry = cache.get(repo)
if entry and "fetched_at" in entry:
fetched = datetime.fromisoformat(entry["fetched_at"])
age_hours = (now - fetched).total_seconds() / 3600
if age_hours < CACHE_MAX_AGE_HOURS:
if now - fetched < max_age:
continue
to_fetch.append(repo)