perf: new file-based cache that ensures correct rtp order (#532)

* perf: new file-based cache that ensures rtp is alweays correct and will cache all files, including those after startup

* refactor: new cache

* test: fix tests

* fix(cache): cache file names on Windows

* feat(cache): allow to disable the cache

* docs: updated cache settings
This commit is contained in:
Folke Lemaitre 2023-02-13 12:01:56 +01:00 committed by GitHub
parent 06f835d0b4
commit 462633bae1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 354 additions and 549 deletions

View file

@ -72,7 +72,7 @@ function M.install_missing()
-- remove and installed plugins from indexed, so cache will index again
for _, p in pairs(Config.plugins) do
if p._.installed then
Cache.indexed[p.dir] = nil
Cache.reset(p.dir)
end
end
-- reload plugins
@ -341,7 +341,7 @@ function M.get_main(plugin)
local normname = Util.normname(plugin.name)
---@type string[]
local mods = {}
for _, modname in ipairs(Cache.get_topmods(plugin.dir)) do
for modname, _ in pairs(Cache.lsmod(plugin.dir)) do
mods[#mods + 1] = modname
local modnorm = Util.normname(modname)
-- if we found an exact match, then use that
@ -450,4 +450,28 @@ function M.colorscheme(name)
end
end
---@param modname string
function M.loader(modname)
local modpath = Cache.find(modname, { rtp = false, paths = Util.get_unloaded_rtp(modname) })
if modpath then
local plugin = Plugin.find(modpath)
if plugin and modpath:find(plugin.dir, 1, true) == 1 then
-- don't load if we're loading specs or if the plugin is already loaded
if not (Plugin.loading or plugin._.loaded) then
if plugin.module == false then
error("Plugin " .. plugin.name .. " is not loaded and is configured with module=false")
end
M.load(plugin, { require = modname })
end
local mod = package.loaded[modname]
if type(mod) == "table" then
return function()
return mod
end
end
return loadfile(modpath)
end
end
end
return M