fix(cache): contest override
This commit is contained in:
parent
a725925434
commit
18dbcd43d2
3 changed files with 11 additions and 9 deletions
|
|
@ -92,9 +92,7 @@ end
|
||||||
---@param platform string
|
---@param platform string
|
||||||
---@param contest_id string
|
---@param contest_id string
|
||||||
---@param problems Problem[]
|
---@param problems Problem[]
|
||||||
---@param contest_name? string
|
function M.set_contest_data(platform, contest_id, problems)
|
||||||
---@param display_name? string
|
|
||||||
function M.set_contest_data(platform, contest_id, problems, contest_name, display_name)
|
|
||||||
vim.validate({
|
vim.validate({
|
||||||
platform = { platform, 'string' },
|
platform = { platform, 'string' },
|
||||||
contest_id = { contest_id, 'string' },
|
contest_id = { contest_id, 'string' },
|
||||||
|
|
@ -102,9 +100,11 @@ function M.set_contest_data(platform, contest_id, problems, contest_name, displa
|
||||||
})
|
})
|
||||||
|
|
||||||
cache_data[platform] = cache_data[platform] or {}
|
cache_data[platform] = cache_data[platform] or {}
|
||||||
|
local prev = cache_data[platform][contest_id] or {}
|
||||||
|
|
||||||
local out = {
|
local out = {
|
||||||
name = contest_name,
|
name = prev.name,
|
||||||
display_name = display_name,
|
display_name = prev.display_name,
|
||||||
problems = vim.deepcopy(problems),
|
problems = vim.deepcopy(problems),
|
||||||
index_map = {},
|
index_map = {},
|
||||||
}
|
}
|
||||||
|
|
@ -151,7 +151,7 @@ function M.get_test_cases(platform, contest_id, problem_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
local index = cache_data[platform][contest_id].index_map[problem_id]
|
local index = cache_data[platform][contest_id].index_map[problem_id]
|
||||||
return cache_data[platform][contest_id].problems[index].test_cases
|
return cache_data[platform][contest_id].problems[index].test_cases or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param platform string
|
---@param platform string
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M.log(msg, level, override)
|
function M.log(msg, level, override)
|
||||||
|
local debug = require('cp.config').get_config().debug or false
|
||||||
level = level or vim.log.levels.INFO
|
level = level or vim.log.levels.INFO
|
||||||
if level >= vim.log.levels.WARN or override then
|
if level >= vim.log.levels.WARN or override or debug then
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
vim.notify(('[cp.nvim]: %s'):format(msg), level)
|
vim.notify(('[cp.nvim]: %s'):format(msg), level)
|
||||||
end)
|
end)
|
||||||
|
|
|
||||||
|
|
@ -63,10 +63,11 @@ function M.setup_contest(platform, contest_id, language, problem_id)
|
||||||
M.setup_problem(pid, language)
|
M.setup_problem(pid, language)
|
||||||
|
|
||||||
local cached_len = #vim.tbl_filter(function(p)
|
local cached_len = #vim.tbl_filter(function(p)
|
||||||
return cache.get_test_cases(platform, contest_id, p.id) ~= nil
|
return not vim.tbl_isempty(cache.get_test_cases(platform, contest_id, p.id))
|
||||||
end, problems)
|
end, problems)
|
||||||
|
|
||||||
if cached_len ~= #problems then
|
if cached_len ~= #problems then
|
||||||
|
logger.log(('Found %s problems, expected %s; re-fetching'):format(cached_len, #problems))
|
||||||
scraper.scrape_all_tests(platform, contest_id, function(ev)
|
scraper.scrape_all_tests(platform, contest_id, function(ev)
|
||||||
local cached_tests = {}
|
local cached_tests = {}
|
||||||
for i, t in ipairs(ev.tests) do
|
for i, t in ipairs(ev.tests) do
|
||||||
|
|
@ -89,7 +90,7 @@ function M.setup_contest(platform, contest_id, language, problem_id)
|
||||||
logger.log('Fetching contests problems...', vim.log.levels.INFO, true)
|
logger.log('Fetching contests problems...', vim.log.levels.INFO, true)
|
||||||
scraper.scrape_contest_metadata(platform, contest_id, function(result)
|
scraper.scrape_contest_metadata(platform, contest_id, function(result)
|
||||||
local problems = result.problems or {}
|
local problems = result.problems or {}
|
||||||
cache.set_contest_data(platform, contest_id, problems, result.name, result.display_name)
|
cache.set_contest_data(platform, contest_id, problems)
|
||||||
logger.log(('Found %d problems for %s contest %s.'):format(#problems, platform, contest_id))
|
logger.log(('Found %d problems for %s contest %s.'):format(#problems, platform, contest_id))
|
||||||
proceed(cache.get_contest_data(platform, contest_id))
|
proceed(cache.get_contest_data(platform, contest_id))
|
||||||
end)
|
end)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue