Reduces the number of files open by housekeeping.lua

This commit is contained in:
Simone Mainardi 2017-11-23 16:16:14 +01:00
parent 46439a8c02
commit 3509b783f5
7 changed files with 67 additions and 50 deletions

View file

@ -3521,48 +3521,6 @@ function path_get_page(path)
return path
end
-- ###########################################
function savePrefsToDisk()
local dirs = ntop.getDirs()
local where = os_utils.fixPath(dirs.workingdir.."/runtimeprefs.json")
local keys = ntop.getKeysCache("ntopng.prefs.*")
local out = {}
for k in pairs(keys or {}) do
out[k] = ntop.dumpCache(k)
end
local json = require("dkjson")
local dump = json.encode(out, nil, 1)
local file = io.open(where, "w")
file:write(dump)
file:close()
end
-- ###########################################
function readPrefsFromDisk()
local dirs = ntop.getDirs()
local where = os_utils.fixPath(dirs.workingdir.."/runtimeprefs.json")
local file = io.open(where, "r")
if(file ~= nil) then
local dump = file:read()
file:close()
local json = require("dkjson")
local restore = json.decode(dump, 1, nil)
for k,v in pairs(restore or {}) do
-- print(k.."\n")
ntop.delCache(k)
ntop.restoreCache(k,v)
end
end
end
-- ###########################################
--
-- IMPORTANT