fix: 7 bugs — parse_mode, /removeplayer, SNo>300, fd leak, warmup sleep, warmup range, dupe print
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 6s

- cancel_sub: add parse_mode=MARKDOWN_V2 so users don't see literal backslashes
- /removeplayer: add CommandHandler that was advertised in /start but missing from handlers
- parse_standings: raise SNo limit 300→5000 to support large open tournaments
- call_bbp_with_checklist: close mkstemp fd to fix resource leak
- _warmup_cache_sync: make time.sleep(1.0) conditional on HTTP fetch, skip for cache hits
- _warmup_cache_sync: derive start_tnr from max(max_tnr_seen, max cached tnr) instead of hardcoded 1445000
- main: remove duplicate print('Client bot started') after blocking run_polling()

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
vrubel 2026-06-22 20:49:28 +00:00
parent 77c8a87e16
commit dd0dd5643d
4 changed files with 36 additions and 15 deletions

View file

@ -753,17 +753,28 @@ async def warmup_cache(context):
def _warmup_cache_sync():
"""Scan the 1.4M cluster at step 1, caching ALL valid TNRs with players.
One-time cost ~40 min, then all searches are instant SQL queries.
"""Scan ~12 000 TNRs from current max downwards, caching valid ones.
Starts from max(max_tnr_seen, max cached tnr, 1445000) so it stays current.
Saves progress to tnr_state so it resumes after restart."""
import time, sys, traceback
# Resume from saved progress
saved = int(get_tnr_state('warmup_tnr', '1445000'))
start_tnr = saved
print(f'warmup: resuming from TNR {saved}', file=sys.stderr)
# Resume from saved progress, or start from current max_tnr if fresh run.
# Default fallback kept so warmup doesn't probe 0 on a brand-new install.
saved_raw = get_tnr_state('warmup_tnr', '')
if saved_raw and saved_raw != 'done':
start_tnr = int(saved_raw)
else:
conn = _get_conn()
row = conn.execute('SELECT MAX(tnr) FROM tnr_cache').fetchone()
conn.close()
max_cached = row[0] if row and row[0] else 0
saved_state = int(get_tnr_state('max_tnr_seen', '1445000'))
start_tnr = max(max_cached, saved_state, 1445000)
end_tnr = max(1, start_tnr - 12000)
print(f'warmup: resuming from TNR {start_tnr} down to {end_tnr}', file=sys.stderr)
for tnr in range(start_tnr, 1433999, -1):
for tnr in range(start_tnr, end_tnr, -1):
already_cached = _get_cached_tnr(tnr) is not None
try:
_fetch_and_parse_art0(tnr)
except Exception as e:
@ -776,9 +787,9 @@ def _warmup_cache_sync():
set_tnr_state('warmup_tnr', str(tnr))
if tnr % 500 == 0:
print(f'warmup: progress TNR {tnr} (started at {start_tnr})', file=sys.stderr)
# Rate-limit: ~1 req/sec to stay within chess-results.com daily limit.
# Cached TNRs return instantly (no HTTP), so this only applies to misses.
time.sleep(1.0)
# Rate-limit: only for HTTP fetches; cached hits return instantly.
if not already_cached:
time.sleep(1.0)
# Mark warmup as complete — next run will see this and skip
set_tnr_state('warmup_tnr', 'done')