* Reintegrated fastindex support
This commit is contained in:
parent
fbe3f6f09f
commit
08e85e726c
1 changed files with 17 additions and 8 deletions
|
@ -49,6 +49,9 @@ dispatched = nil
|
||||||
built_index = false
|
built_index = false
|
||||||
built_tree = false
|
built_tree = false
|
||||||
|
|
||||||
|
-- Fastindex
|
||||||
|
local fi
|
||||||
|
|
||||||
|
|
||||||
-- Builds a URL
|
-- Builds a URL
|
||||||
function build_url(...)
|
function build_url(...)
|
||||||
|
@ -157,22 +160,22 @@ function createindex()
|
||||||
local path = luci.sys.libpath() .. "/controller/"
|
local path = luci.sys.libpath() .. "/controller/"
|
||||||
local suff = ".lua"
|
local suff = ".lua"
|
||||||
|
|
||||||
--[[if pcall(require, "fastindex") then
|
if pcall(require, "luci.fastindex") then
|
||||||
createindex_fastindex(path, suff)
|
createindex_fastindex(path, suff)
|
||||||
else
|
else
|
||||||
createindex_plain(path, suff)
|
createindex_plain(path, suff)
|
||||||
end]]--
|
end
|
||||||
|
|
||||||
createindex_plain(path, suff)
|
|
||||||
|
|
||||||
built_index = true
|
built_index = true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Uses fastindex to create the dispatching tree
|
-- Uses fastindex to create the dispatching tree
|
||||||
function createindex_fastindex(path, suffix)
|
function createindex_fastindex(path, suffix)
|
||||||
local fi = fastindex.new("index")
|
if not fi then
|
||||||
|
fi = luci.fastindex.new("index")
|
||||||
fi.add(path .. "*" .. suffix)
|
fi.add(path .. "*" .. suffix)
|
||||||
fi.add(path .. "*/*" .. suffix)
|
fi.add(path .. "*/*" .. suffix)
|
||||||
|
end
|
||||||
fi.scan()
|
fi.scan()
|
||||||
|
|
||||||
for k, v in pairs(fi.indexes) do
|
for k, v in pairs(fi.indexes) do
|
||||||
|
@ -181,7 +184,12 @@ function createindex_fastindex(path, suffix)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Calls the index function of all available controllers
|
-- Calls the index function of all available controllers
|
||||||
|
-- Fallback for transition purposes / Leave it in as long as it works otherwise throw it away
|
||||||
function createindex_plain(path, suffix)
|
function createindex_plain(path, suffix)
|
||||||
|
if built_index then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local cache = nil
|
local cache = nil
|
||||||
|
|
||||||
local controllers = luci.util.combine(
|
local controllers = luci.util.combine(
|
||||||
|
@ -201,11 +209,12 @@ function createindex_plain(path, suffix)
|
||||||
|
|
||||||
for i,c in ipairs(controllers) do
|
for i,c in ipairs(controllers) do
|
||||||
local module = "luci.controller." .. c:sub(#path+1, #c-#suffix):gsub("/", ".")
|
local module = "luci.controller." .. c:sub(#path+1, #c-#suffix):gsub("/", ".")
|
||||||
local cachefile = indexcache .. "/" .. module
|
local cachefile
|
||||||
local stime
|
local stime
|
||||||
local ctime
|
local ctime
|
||||||
|
|
||||||
if cache then
|
if cache then
|
||||||
|
cachefile = indexcache .. "/" .. module
|
||||||
stime = luci.fs.mtime(c) or 0
|
stime = luci.fs.mtime(c) or 0
|
||||||
ctime = luci.fs.mtime(cachefile) or 0
|
ctime = luci.fs.mtime(cachefile) or 0
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue