From dc262009f9092665a4262335dad133c6c62b6f3c Mon Sep 17 00:00:00 2001 From: jwkim Date: Mon, 15 Jun 2026 16:08:30 +0900 Subject: [PATCH] Speed up football refresh (batch 24) + skip caching on API errors --- backend/app/config.py | 5 +++-- backend/app/services/football_data.py | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/backend/app/config.py b/backend/app/config.py index 417d655..4690353 100644 --- a/backend/app/config.py +++ b/backend/app/config.py @@ -118,8 +118,9 @@ class Settings(BaseSettings): football_api_base: str = "https://v3.football.api-sports.io" # 캐시 신선도(시간). 이 시간 지난 팀만 워커가 재수집(랭킹/폼은 자주 안 변함). football_cache_ttl_hours: int = 168 # 7일 - # 수집 잡 1회당 갱신할 최대 팀 수(무료 100/일·10/분 제한 분산). - football_refresh_batch: int = 8 + # 수집 잡 1회당 갱신할 최대 팀 수. 팀당 ~3콜이라 24팀≈72콜(무료 100/일 안). + # 24면 48팀이 약 2일에 채워짐(8이면 6일). 한도 소진 시 남은 팀은 다음 잡에서. + football_refresh_batch: int = 24 # API 호출 간 최소 간격(초) — 무료 10req/분 제한 회피. football_call_interval_sec: float = 7.0 # 수집 잡 시각(KST) — 예측 생성(00:05)보다 앞서 캐시를 채워둔다. diff --git a/backend/app/services/football_data.py b/backend/app/services/football_data.py index 73303a3..1106ec3 100644 --- a/backend/app/services/football_data.py +++ b/backend/app/services/football_data.py @@ -87,8 +87,14 @@ async def _get(client: httpx.AsyncClient, path: str, **params) -> dict: timeout=25, ) r.raise_for_status() + data = r.json() + # API-Football 은 한도초과·레이트·파라미터 오류를 HTTP 200 + errors 로 준다. + # 빈 응답을 정상으로 오해해 빈 데이터를 캐싱하지 않도록 여기서 예외 발생. + errs = data.get("errors") + if errs: # 빈 리스트([])는 정상, 채워진 dict 면 오류 + raise RuntimeError(f"API-Football error: {errs}") await asyncio.sleep(settings.football_call_interval_sec) # 10/분 제한 회피 - return r.json() + return data # ── 캐시 upsert ────────────────────────────────────────────────