diff options
author | Ansuel Smith <ansuelsmth@gmail.com> | 2018-05-24 02:03:03 +0200 |
---|---|---|
committer | Ansuel Smith <ansuelsmth@gmail.com> | 2018-06-02 18:52:22 +0200 |
commit | 299121fc84b1e00650c9c976c0a847cd67e46eb0 (patch) | |
tree | 76820ad47b25f318415330d74b9a78c9e84d151b /applications/luci-app-ddns/luasrc/controller/ddns.lua | |
parent | 7acacf2cf806c5d74fc60f8a2de95628ba52bb7d (diff) |
luci-app-ddns: improve performance
Every request directed to the ddns app call ddns tools module.
Ddns tools module have lots of global variable that call slow os.execute function. This adds 10 second to every ddns request even if the function that is requested doesn't need that global variable. This commit introduce env_info function that execute os.execute command by executing what is actually requested and not process all the variables. Also remove 2 unecessary module that are not used. More researh find that major slowdown was caused by the calling of ddns script for the version check. Now we check if opkg is present and use it to check ddns-scripts version.
Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
Diffstat (limited to 'applications/luci-app-ddns/luasrc/controller/ddns.lua')
-rwxr-xr-x | applications/luci-app-ddns/luasrc/controller/ddns.lua | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/applications/luci-app-ddns/luasrc/controller/ddns.lua b/applications/luci-app-ddns/luasrc/controller/ddns.lua index 5f4a5118c3..bfd7a2a414 100755 --- a/applications/luci-app-ddns/luasrc/controller/ddns.lua +++ b/applications/luci-app-ddns/luasrc/controller/ddns.lua @@ -21,7 +21,6 @@ luci_helper = "/usr/lib/ddns/dynamic_dns_lucihelper.sh" local srv_name = "ddns-scripts" local srv_ver_min = "2.7.7" -- minimum version of service required -local srv_ver_cmd = luci_helper .. [[ -V | awk {'print $2'}]] local app_name = "luci-app-ddns" local app_title = "Dynamic DNS" local app_version = "2.4.9-1" @@ -29,7 +28,6 @@ local app_version = "2.4.9-1" function index() local nxfs = require "nixio.fs" -- global definitions not available local sys = require "luci.sys" -- in function index() - local ddns = require "luci.tools.ddns" -- ddns multiused functions local muci = require "luci.model.uci" -- no config create an empty one @@ -81,26 +79,41 @@ end -- Standardized application/service functions function app_title_main() - return [[<a href="javascript:alert(']] - .. I18N.translate("Version Information") - .. [[\n\n]] .. app_name - .. [[\n\t]] .. I18N.translate("Version") .. [[:\t]] .. app_version - .. [[\n\n]] .. srv_name .. [[ ]] .. I18N.translate("required") .. [[:]] - .. [[\n\t]] .. I18N.translate("Version") .. [[:\t]] - .. srv_ver_min .. [[ ]] .. I18N.translate("or higher") - .. [[\n\n]] .. srv_name .. [[ ]] .. I18N.translate("installed") .. [[:]] - .. [[\n\t]] .. I18N.translate("Version") .. [[:\t]] - .. (service_version() or I18N.translate("NOT installed")) - .. [[\n\n]] - .. [[')">]] - .. I18N.translate(app_title) - .. [[</a>]] + tmp = {} + tmp[#tmp+1] = [[<a href="javascript:alert(']] + tmp[#tmp+1] = I18N.translate("Version Information") + tmp[#tmp+1] = [[\n\n]] .. app_name + tmp[#tmp+1] = [[\n\t]] .. I18N.translate("Version") .. [[:\t]] .. app_version + tmp[#tmp+1] = [[\n\n]] .. srv_name .. [[ ]] .. I18N.translate("required") .. [[:]] + tmp[#tmp+1] = [[\n\t]] .. I18N.translate("Version") .. [[:\t]] + tmp[#tmp+1] = srv_ver_min .. [[ ]] .. I18N.translate("or higher") + tmp[#tmp+1] = [[\n\n]] .. srv_name .. [[ ]] .. I18N.translate("installed") .. [[:]] + tmp[#tmp+1] = [[\n\t]] .. I18N.translate("Version") .. [[:\t]] + tmp[#tmp+1] = (service_version() or I18N.translate("NOT installed")) + tmp[#tmp+1] = [[\n\n]] + tmp[#tmp+1] = [[')">]] + tmp[#tmp+1] = I18N.translate(app_title) + tmp[#tmp+1] = [[</a>]] + + return table.concat(tmp) end function service_version() - local ver = nil + local nxfs = require "nixio.fs" + + local ver = nil + local ver_helper + + if nxfs.access("/bin/opkg") then + ver_helper = "/bin/opkg info " .. srv_name .. " | grep 'Version'" + else + ver_helper = luci_helper .. " -V" + end + + local srv_ver_cmd = ver_helper .. " | awk {'print $2'} " + ver = UTIL.exec(srv_ver_cmd) - if #ver > 0 then return ver end + if ver and #ver > 0 then return ver end IPKG.list_installed(srv_name, function(n, v, d) if v and (#v > 0) then ver = v end @@ -108,6 +121,7 @@ function service_version() ) return ver end + function service_ok() return IPKG.compare_versions((service_version() or "0"), ">=", srv_ver_min) end |