0
0
mirror of https://github.com/Doodle3D/doodle3d-firmware.git synced 2024-06-26 03:21:22 +02:00

Avoid unnecessary UCI commits, speeding up the process of setting all keys at once considerably.

This commit is contained in:
Wouter R 2013-12-23 18:05:48 +01:00
parent e79902feeb
commit 0a51cee8c9
2 changed files with 12 additions and 3 deletions

View File

@ -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'))

View File

@ -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.