summaryrefslogtreecommitdiffhomepage
path: root/libs/web/luasrc/dispatcher.lua
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-06-01 12:12:18 +0000
committerSteven Barth <steven@midlink.org>2008-06-01 12:12:18 +0000
commitb454395a8da4013aff2ecd64cd7eafc01fc6a5a2 (patch)
tree0071604ca65f1e520ee2f56b6cf6343bc5297df9 /libs/web/luasrc/dispatcher.lua
parent1da5feb9f720fd48a886aad09df91bd8cc9df4c8 (diff)
* Performance optimizations
* libs/core: Added bytecode stripping function to luci.util * libs/core: Added smart indexcache that automatically updates cached index-files on change * libs/web: Enabled template caching support * Core Translation part 4
Diffstat (limited to 'libs/web/luasrc/dispatcher.lua')
-rw-r--r--libs/web/luasrc/dispatcher.lua40
1 files changed, 23 insertions, 17 deletions
diff --git a/libs/web/luasrc/dispatcher.lua b/libs/web/luasrc/dispatcher.lua
index 8d1e493fb8..c7e1ed6fe2 100644
--- a/libs/web/luasrc/dispatcher.lua
+++ b/libs/web/luasrc/dispatcher.lua
@@ -177,7 +177,7 @@ end
-- Calls the index function of all available controllers
function createindex_plain(path, suffix)
- local cachetime = nil
+ local cache = nil
local controllers = luci.util.combine(
luci.fs.glob(path .. "*" .. suffix) or {},
@@ -185,32 +185,38 @@ function createindex_plain(path, suffix)
)
if indexcache then
- cachetime = luci.fs.mtime(indexcache)
+ cache = luci.fs.mtime(indexcache)
- if not cachetime then
+ if not cache then
luci.fs.mkdir(indexcache)
luci.fs.chmod(indexcache, "a=,u=rwx")
+ cache = luci.fs.mtime(indexcache)
end
end
- if not cachetime then
- for i,c in ipairs(controllers) do
- c = "luci.controller." .. c:sub(#path+1, #c-#suffix):gsub("/", ".")
- stat, mod = pcall(require, c)
+ for i,c in ipairs(controllers) do
+ local module = "luci.controller." .. c:sub(#path+1, #c-#suffix):gsub("/", ".")
+ local cachefile = indexcache .. "/" .. module
+ local stime
+ local ctime
+
+ if cache then
+ stime = luci.fs.mtime(c) or 0
+ ctime = luci.fs.mtime(cachefile) or 0
+ end
+
+ if not cache or stime > ctime then
+ stat, mod = pcall(require, module)
if stat and mod and type(mod.index) == "function" then
- index[c] = mod.index
+ index[module] = mod.index
- if indexcache then
- luci.fs.writefile(indexcache .. "/" .. c, string.dump(mod.index))
+ if cache then
+ luci.fs.writefile(cachefile, luci.util.dump(mod.index))
end
end
- end
- else
- for i,c in ipairs(luci.fs.dir(indexcache)) do
- if c:sub(1) ~= "." then
- index[c] = loadfile(indexcache .. "/" .. c)
- end
+ else
+ index[module] = loadfile(cachefile)
end
end
end
@@ -226,7 +232,7 @@ function createtree()
-- Load default translation
luci.i18n.loadc("default")
- local scope = _G
+ local scope = luci.util.clone(_G)
for k,v in pairs(_M) do
if type(v) == "function" then
scope[k] = v