fix: reduce chess-results.com request volume by ~20-50x
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 5s

- check_all_subscriptions: quick pre-check (1 req, art=4 only) before
  full fetch; full fetch only when results_count or current_round changed.
  Interval 60s → 300s. Saves ~10,000 req/day per active subscription.
- rescan_existing_tournaments: filter to tournaments ended within last 30
  days (or no end_date). Drops from ~2000 cached TNRs to ~30-100 active
  ones per run, saving ~22,000 req/day.
- warmup: sleep 1s per TNR instead of 20ms per 500 — spreads initial
  full-scan over hours rather than minutes.
- parser: extract _normalize_url helper, add fetch_tournament_quick().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
vrubel 2026-06-21 07:47:38 +00:00
parent 66b10d9425
commit 8058080c3a
3 changed files with 65 additions and 12 deletions

View file

@ -334,16 +334,47 @@ def extract_tournament_meta(html: str) -> dict:
# ── Full tournament fetch ─────────────────────────────────────
def _normalize_url(url: str) -> str:
base = re.sub(r'[&?]art=\d+', '', url)
base = re.sub(r'[&?]rd=\d+', '', base)
base = re.sub(r'[&?]turdet=\w+', '', base)
base = re.sub(r'[&?]SNode=\w+', '', base)
return base
def fetch_tournament_quick(url: str) -> dict:
"""Lightweight change-detection fetch: only art=4 (1 HTTP request).
Returns standings from the page directly (no art=2 cross-reference).
Use to check if results_count or current_round changed before doing a
full fetch_tournament() call.
"""
base_url = _normalize_url(url)
try:
html = fetch_url(base_url + '&art=4&turdet=YES')
except Exception as e:
raise RuntimeError(f'Не удалось загрузить турнир: {e}')
meta = extract_tournament_meta(html)
standings = parse_standings(html)
current_round = meta['current_round']
if standings:
max_results = max(len(s['results']) for s in standings)
if max_results > current_round:
current_round = max_results
return {
'name': meta['name'],
'num_rounds': meta['num_rounds'],
'current_round': current_round,
'standings': standings,
}
def fetch_tournament(url: str) -> dict:
"""Fetch full tournament data from any chess-results.com URL.
Detects current state automatically (any number of completed rounds).
"""
# Normalize URL to base
base_url = re.sub(r'[&?]art=\d+', '', url)
base_url = re.sub(r'[&?]rd=\d+', '', base_url)
base_url = re.sub(r'[&?]turdet=\w+', '', base_url)
base_url = re.sub(r'[&?]SNode=\w+', '', base_url)
base_url = _normalize_url(url)
# Fetch standings
standings_url = base_url + '&art=4&turdet=YES'