remove ttl
This commit is contained in:
parent
7c337d6b33
commit
bcbcc4365f
2 changed files with 0 additions and 37 deletions
|
|
@ -373,11 +373,6 @@ Picker Controls ~
|
||||||
<c-p> / <up> Navigate to previous item
|
<c-p> / <up> Navigate to previous item
|
||||||
/ Start filtering/searching items
|
/ Start filtering/searching items
|
||||||
|
|
||||||
Notes ~
|
|
||||||
• Contest lists are fetched dynamically using scrapers with a TTL of 1 day
|
|
||||||
• Use <c-r> to force refresh
|
|
||||||
• Large contest lists may take time to load
|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
RUN PANEL *cp-run*
|
RUN PANEL *cp-run*
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,10 @@
|
||||||
---@class ContestListData
|
---@class ContestListData
|
||||||
---@field contests table[]
|
---@field contests table[]
|
||||||
---@field cached_at number
|
---@field cached_at number
|
||||||
---@field expires_at number
|
|
||||||
|
|
||||||
---@class ContestData
|
---@class ContestData
|
||||||
---@field problems Problem[]
|
---@field problems Problem[]
|
||||||
---@field scraped_at string
|
---@field scraped_at string
|
||||||
---@field expires_at? number
|
|
||||||
---@field test_cases? CachedTestCase[]
|
---@field test_cases? CachedTestCase[]
|
||||||
---@field test_cases_cached_at? number
|
---@field test_cases_cached_at? number
|
||||||
---@field timeout_ms? number
|
---@field timeout_ms? number
|
||||||
|
|
@ -39,28 +37,6 @@ local cache_file = vim.fn.stdpath('data') .. '/cp-nvim.json'
|
||||||
local cache_data = {}
|
local cache_data = {}
|
||||||
local loaded = false
|
local loaded = false
|
||||||
|
|
||||||
local CONTEST_LIST_TTL = {
|
|
||||||
cses = 7 * 24 * 60 * 60,
|
|
||||||
codeforces = 24 * 60 * 60,
|
|
||||||
atcoder = 24 * 60 * 60,
|
|
||||||
}
|
|
||||||
|
|
||||||
---@param contest_data ContestData
|
|
||||||
---@param platform string
|
|
||||||
---@return boolean
|
|
||||||
local function is_cache_valid(contest_data, platform)
|
|
||||||
vim.validate({
|
|
||||||
contest_data = { contest_data, 'table' },
|
|
||||||
platform = { platform, 'string' },
|
|
||||||
})
|
|
||||||
|
|
||||||
if contest_data.expires_at and os.time() >= contest_data.expires_at then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.load()
|
function M.load()
|
||||||
if loaded then
|
if loaded then
|
||||||
return
|
return
|
||||||
|
|
@ -125,10 +101,6 @@ function M.get_contest_data(platform, contest_id)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if not is_cache_valid(contest_data, platform) then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
return contest_data
|
return contest_data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -146,11 +118,9 @@ function M.set_contest_data(platform, contest_id, problems)
|
||||||
cache_data[platform] = {}
|
cache_data[platform] = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
local ttl = CONTEST_LIST_TTL[platform] or (24 * 60 * 60)
|
|
||||||
cache_data[platform][contest_id] = {
|
cache_data[platform][contest_id] = {
|
||||||
problems = problems,
|
problems = problems,
|
||||||
scraped_at = os.date('%Y-%m-%d'),
|
scraped_at = os.date('%Y-%m-%d'),
|
||||||
expires_at = os.time() + ttl,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
M.save()
|
M.save()
|
||||||
|
|
@ -316,11 +286,9 @@ function M.set_contest_list(platform, contests)
|
||||||
cache_data.contest_lists = {}
|
cache_data.contest_lists = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
local ttl = CONTEST_LIST_TTL[platform] or (24 * 60 * 60)
|
|
||||||
cache_data.contest_lists[platform] = {
|
cache_data.contest_lists[platform] = {
|
||||||
contests = contests,
|
contests = contests,
|
||||||
cached_at = os.time(),
|
cached_at = os.time(),
|
||||||
expires_at = os.time() + ttl,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
M.save()
|
M.save()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue