remove outdated vars
This commit is contained in:
parent
e66c57530e
commit
0bdf69621e
2 changed files with 22 additions and 22 deletions
|
|
@ -3,15 +3,15 @@ local M = {}
|
|||
local cache_file = vim.fn.stdpath("data") .. "/cp-contest-cache.json"
|
||||
local cache_data = {}
|
||||
|
||||
local function get_expiry_date(contest_type)
|
||||
if contest_type == "cses" then
|
||||
local function get_expiry_date(platform)
|
||||
if platform == "cses" then
|
||||
return os.time() + (30 * 24 * 60 * 60)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function is_cache_valid(contest_data, contest_type)
|
||||
if contest_type ~= "cses" then
|
||||
local function is_cache_valid(contest_data, platform)
|
||||
if platform ~= "cses" then
|
||||
return true
|
||||
end
|
||||
|
||||
|
|
@ -49,40 +49,40 @@ function M.save()
|
|||
vim.fn.writefile(vim.split(encoded, "\n"), cache_file)
|
||||
end
|
||||
|
||||
function M.get_contest_data(contest_type, contest_id)
|
||||
if not cache_data[contest_type] then
|
||||
function M.get_contest_data(platform, contest_id)
|
||||
if not cache_data[platform] then
|
||||
return nil
|
||||
end
|
||||
|
||||
local contest_data = cache_data[contest_type][contest_id]
|
||||
local contest_data = cache_data[platform][contest_id]
|
||||
if not contest_data then
|
||||
return nil
|
||||
end
|
||||
|
||||
if not is_cache_valid(contest_data, contest_type) then
|
||||
if not is_cache_valid(contest_data, platform) then
|
||||
return nil
|
||||
end
|
||||
|
||||
return contest_data
|
||||
end
|
||||
|
||||
function M.set_contest_data(contest_type, contest_id, problems)
|
||||
if not cache_data[contest_type] then
|
||||
cache_data[contest_type] = {}
|
||||
function M.set_contest_data(platform, contest_id, problems)
|
||||
if not cache_data[platform] then
|
||||
cache_data[platform] = {}
|
||||
end
|
||||
|
||||
cache_data[contest_type][contest_id] = {
|
||||
cache_data[platform][contest_id] = {
|
||||
problems = problems,
|
||||
scraped_at = os.date("%Y-%m-%d"),
|
||||
expires_at = get_expiry_date(contest_type),
|
||||
expires_at = get_expiry_date(platform),
|
||||
}
|
||||
|
||||
M.save()
|
||||
end
|
||||
|
||||
function M.clear_contest_data(contest_type, contest_id)
|
||||
if cache_data[contest_type] and cache_data[contest_type][contest_id] then
|
||||
cache_data[contest_type][contest_id] = nil
|
||||
function M.clear_contest_data(platform, contest_id)
|
||||
if cache_data[platform] and cache_data[platform][contest_id] then
|
||||
cache_data[platform][contest_id] = nil
|
||||
M.save()
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue