From 3ec5a2ce4c99202dfa76970bbaa36bfa05230cb5 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Tue, 29 Nov 2022 23:16:21 +0100 Subject: [PATCH] perf: run cache autosave after loading --- lua/lazy/core/cache.lua | 49 ++++++++++++++++++++-------------------- lua/lazy/core/config.lua | 2 ++ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/lua/lazy/core/cache.lua b/lua/lazy/core/cache.lua index 1fbc24a..270d6b5 100644 --- a/lua/lazy/core/cache.lua +++ b/lua/lazy/core/cache.lua @@ -44,7 +44,30 @@ function M.hash(file) end function M.setup() - M.load() + cache = {} + local f = io.open(cache_path, "rb") + if f then + cache_hash = M.hash(cache_path) + ---@type string + local data = f:read("*a") + f:close() + + local from = 1 + local to = data:find("\0", from, true) + while to do + local key = data:sub(from, to - 1) + from = to + 1 + to = data:find("\0", from, true) + local len = tonumber(data:sub(from, to - 1)) + from = to + 1 + cache[key] = data:sub(from, from + len - 1) + from = from + len + to = data:find("\0", from, true) + end + end +end + +function M.autosave() vim.api.nvim_create_autocmd("User", { pattern = "LazyDone", once = true, @@ -77,28 +100,4 @@ function M.save() f:close() end -function M.load() - cache = {} - local f = io.open(cache_path, "rb") - if f then - cache_hash = M.hash(cache_path) - ---@type string - local data = f:read("*a") - f:close() - - local from = 1 - local to = data:find("\0", from, true) - while to do - local key = data:sub(from, to - 1) - from = to + 1 - to = data:find("\0", from, true) - local len = tonumber(data:sub(from, to - 1)) - from = to + 1 - cache[key] = data:sub(from, from + len - 1) - from = from + len - to = data:find("\0", from, true) - end - end -end - return M diff --git a/lua/lazy/core/config.lua b/lua/lazy/core/config.lua index 800eefb..641c94f 100644 --- a/lua/lazy/core/config.lua +++ b/lua/lazy/core/config.lua @@ -27,6 +27,7 @@ M.defaults = { task = "✔ ", }, }, + install_missing = true, git = { -- defaults for `Lazy log` log = { "-10" }, -- last 10 commits @@ -67,6 +68,7 @@ function M.setup(opts) pattern = "VeryLazy", once = true, callback = function() + require("lazy.core.cache").autosave() require("lazy.view").setup() end, })