From 0bdf69621ebfa0b4256a9b5554cd830d2afae453 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 13 Sep 2025 23:52:36 -0500 Subject: [PATCH] remove outdated vars --- lua/cp/cache.lua | 32 ++++++++++++++++---------------- lua/cp/scrape.lua | 12 ++++++------ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lua/cp/cache.lua b/lua/cp/cache.lua index 0294b50..12da837 100644 --- a/lua/cp/cache.lua +++ b/lua/cp/cache.lua @@ -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 diff --git a/lua/cp/scrape.lua b/lua/cp/scrape.lua index 62188d9..c2436e4 100644 --- a/lua/cp/scrape.lua +++ b/lua/cp/scrape.lua @@ -36,13 +36,13 @@ local function setup_python_env() return true end ----@param contest_type string +---@param platform string ---@param contest_id string ---@return {success: boolean, problems?: table[], error?: string} -function M.scrape_contest_metadata(contest_type, contest_id) +function M.scrape_contest_metadata(platform, contest_id) cache.load() - local cached_data = cache.get_contest_data(contest_type, contest_id) + local cached_data = cache.get_contest_data(platform, contest_id) if cached_data then return { success = true, @@ -58,7 +58,7 @@ function M.scrape_contest_metadata(contest_type, contest_id) end local plugin_path = get_plugin_path() - local scraper_path = plugin_path .. "/scrapers/" .. contest_type .. ".py" + local scraper_path = plugin_path .. "/scrapers/" .. platform .. ".py" local args = { "uv", "run", scraper_path, "metadata", contest_id } local result = vim.system(args, { @@ -87,13 +87,13 @@ function M.scrape_contest_metadata(contest_type, contest_id) end local problems_list - if contest_type == "cses" then + if platform == "cses" then problems_list = data.categories and data.categories["CSES Problem Set"] or {} else problems_list = data.problems or {} end - cache.set_contest_data(contest_type, contest_id, problems_list) + cache.set_contest_data(platform, contest_id, problems_list) return { success = true, problems = problems_list,