From 0a51cee8c976c16921dc74fba8c189a47dc7cd2d Mon Sep 17 00:00:00 2001 From: Wouter R Date: Mon, 23 Dec 2013 18:05:48 +0100 Subject: [PATCH] Avoid unnecessary UCI commits, speeding up the process of setting all keys at once considerably. --- src/rest/api/api_config.lua | 4 +++- src/util/settings.lua | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/rest/api/api_config.lua b/src/rest/api/api_config.lua index 3a2711e..00d8be1 100644 --- a/src/rest/api/api_config.lua +++ b/src/rest/api/api_config.lua @@ -66,7 +66,7 @@ function M._global_POST(request, response) local validation = {} for k,v in pairs(request:getAll()) do --log:info(" "..k..": "..v); - local r,m = settings.set(k, v) + local r,m = settings.set(k, v, true) if r then validation[k] = "ok" @@ -74,10 +74,12 @@ function M._global_POST(request, response) validation[k] = "could not save setting ('" .. m .. "')" log:info(" m: "..utils.dump(m)) elseif r == nil then + settings.commit() response:setError(m) return end end + settings.commit() response:addData("validation",validation) local substitutedSsid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid')) diff --git a/src/util/settings.lua b/src/util/settings.lua index 6ec3fab..34c7c5e 100644 --- a/src/util/settings.lua +++ b/src/util/settings.lua @@ -235,9 +235,10 @@ end --- Sets a key to a new value or reverts it to the default value. -- @string key The key to set. -- @p[opt=nil] value The value or set, or nil to revert key to its default value. +-- @p[opt=nil] noCommit If true, do not commit the uci configuration; this is more efficient when setting multiple values -- @treturn bool|nil True if everything went well, false if validation error, nil in case of error. -- @treturn ?string Error message in case first return value is nil (invalid key). -function M.set(key, value) +function M.set(key, value, noCommit) log:info("settings:set: "..utils.dump(key).." to: "..utils.dump(value)) key = replaceDots(key) @@ -299,10 +300,16 @@ function M.set(key, value) end end - uci:commit(UCI_CONFIG_NAME) + if noCommit ~= true then uci:commit(UCI_CONFIG_NAME) end return true end +--- Commit the UCI configuration, this can be used after making multiple changes +-- which have not been committed yet. +function M.commit() + uci:commit(UCI_CONFIG_NAME) +end + --- Reset all settings to their default values -- @string key The key to set. -- @treturn bool|nil True if everything went well, nil in case of error.