feat(race): add supports_countdown to ContestListResult

Problem: `:CP race` on platforms without future contests (CSES, USACO)
wastes time fetching the full contest list only to discover there is
no `start_time`. The error message is also uninformative.

Solution: Add `supports_countdown` bool to `ContestListResult` (default
`True`). CSES and USACO set it to `False`. Cache the flag per-platform
so subsequent calls skip the fetch entirely. `race.lua` checks the
cached value first, then the scraper result, and shows
`"<Platform> does not support :CP race"` instead of a generic error.
This commit is contained in:
Barrett Ruth 2026-03-06 18:01:08 -05:00
parent 592f977296
commit 4e709c8470
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
7 changed files with 62 additions and 16 deletions

View file

@ -35,20 +35,36 @@ function M.start(platform, contest_id, language)
end
cache.load()
local display = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
local cached_countdown = cache.get_supports_countdown(platform)
if cached_countdown == false then
logger.log(('%s does not support :CP race'):format(display), { level = vim.log.levels.ERROR })
return
end
local start_time = cache.get_contest_start_time(platform, contest_id)
if not start_time then
logger.log('Fetching contest list...', { level = vim.log.levels.INFO, override = true })
local contests = scraper.scrape_contest_list(platform)
if contests and #contests > 0 then
cache.set_contest_summaries(platform, contests)
start_time = cache.get_contest_start_time(platform, contest_id)
logger.log('Fetching contest list...', { level = vim.log.levels.INFO, override = true, sync = true })
local result = scraper.scrape_contest_list(platform)
if result then
local sc = result.supports_countdown
if sc == false then
cache.set_contest_summaries(platform, result.contests or {}, { supports_countdown = false })
logger.log(('%s does not support :CP race'):format(display), { level = vim.log.levels.ERROR })
return
end
if result.contests and #result.contests > 0 then
cache.set_contest_summaries(platform, result.contests, { supports_countdown = sc })
start_time = cache.get_contest_start_time(platform, contest_id)
end
end
end
if not start_time then
logger.log(
('No start time found for %s contest %s'):format(
('No start time found for %s contest "%s"'):format(
constants.PLATFORM_DISPLAY_NAMES[platform] or platform,
contest_id
),