From be1bc2095e524d0aa7021f2dc51b240c2e94194e Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 7 Mar 2026 19:46:28 -0500 Subject: [PATCH] refactor(cache): remove file-based credential storage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: `cache.lua` stored credentials in `_credentials` keys inside the JSON cache file, with a versioned migration system (`CACHE_VERSION`) that only existed to move credentials between formats. Solution: remove `get_credentials`, `set_credentials`, `clear_credentials`, the v1→v2 migration, and `CACHE_VERSION`. The cache file is now a plain JSON blob with no version field. --- lua/cp/cache.lua | 52 +----------------------------------------------- 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/lua/cp/cache.lua b/lua/cp/cache.lua index 6d56228..14659b2 100644 --- a/lua/cp/cache.lua +++ b/lua/cp/cache.lua @@ -42,13 +42,10 @@ local M = {} -local CACHE_VERSION = 2 - local cache_file = vim.fn.stdpath('data') .. '/cp-nvim.json' local cache_data = {} local loaded = false ---- Load the cache from disk if not done already ---@return nil function M.load() if loaded then @@ -73,26 +70,7 @@ function M.load() end local ok, decoded = pcall(vim.json.decode, table.concat(content, '\n')) - if not ok then - cache_data = {} - M.save() - loaded = true - return - end - - if decoded._version == 1 then - local old_creds = decoded._credentials - decoded._credentials = nil - if old_creds then - for platform, creds in pairs(old_creds) do - decoded[platform] = decoded[platform] or {} - decoded[platform]._credentials = creds - end - end - decoded._version = CACHE_VERSION - cache_data = decoded - M.save() - elseif decoded._version == CACHE_VERSION then + if ok and type(decoded) == 'table' then cache_data = decoded else cache_data = {} @@ -101,13 +79,10 @@ function M.load() loaded = true end ---- Save the cache to disk, overwriting existing contents ---@return nil function M.save() vim.schedule(function() vim.fn.mkdir(vim.fn.fnamemodify(cache_file, ':h'), 'p') - - cache_data._version = CACHE_VERSION local encoded = vim.json.encode(cache_data) local lines = vim.split(encoded, '\n') local tmpfile = vim.fn.tempname() @@ -450,31 +425,6 @@ function M.get_contest_display_name(platform, contest_id) return cache_data[platform][contest_id].display_name end ----@param platform string ----@return table? -function M.get_credentials(platform) - if not cache_data[platform] then - return nil - end - return cache_data[platform]._credentials -end - ----@param platform string ----@param creds table -function M.set_credentials(platform, creds) - cache_data[platform] = cache_data[platform] or {} - cache_data[platform]._credentials = creds - M.save() -end - ----@param platform string -function M.clear_credentials(platform) - if cache_data[platform] then - cache_data[platform]._credentials = nil - end - M.save() -end - ---@return nil function M.clear_all() cache_data = {}