mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 11:03:48 +01:00
Avoid unnecessary UCI commits, speeding up the process of setting all keys at once considerably.
This commit is contained in:
parent
e79902feeb
commit
0a51cee8c9
@ -66,7 +66,7 @@ function M._global_POST(request, response)
|
|||||||
local validation = {}
|
local validation = {}
|
||||||
for k,v in pairs(request:getAll()) do
|
for k,v in pairs(request:getAll()) do
|
||||||
--log:info(" "..k..": "..v);
|
--log:info(" "..k..": "..v);
|
||||||
local r,m = settings.set(k, v)
|
local r,m = settings.set(k, v, true)
|
||||||
|
|
||||||
if r then
|
if r then
|
||||||
validation[k] = "ok"
|
validation[k] = "ok"
|
||||||
@ -74,10 +74,12 @@ function M._global_POST(request, response)
|
|||||||
validation[k] = "could not save setting ('" .. m .. "')"
|
validation[k] = "could not save setting ('" .. m .. "')"
|
||||||
log:info(" m: "..utils.dump(m))
|
log:info(" m: "..utils.dump(m))
|
||||||
elseif r == nil then
|
elseif r == nil then
|
||||||
|
settings.commit()
|
||||||
response:setError(m)
|
response:setError(m)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
settings.commit()
|
||||||
response:addData("validation",validation)
|
response:addData("validation",validation)
|
||||||
|
|
||||||
local substitutedSsid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid'))
|
local substitutedSsid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid'))
|
||||||
|
@ -235,9 +235,10 @@ end
|
|||||||
--- Sets a key to a new value or reverts it to the default value.
|
--- Sets a key to a new value or reverts it to the default value.
|
||||||
-- @string key The key to set.
|
-- @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] 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 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).
|
-- @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))
|
log:info("settings:set: "..utils.dump(key).." to: "..utils.dump(value))
|
||||||
key = replaceDots(key)
|
key = replaceDots(key)
|
||||||
|
|
||||||
@ -299,10 +300,16 @@ function M.set(key, value)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
uci:commit(UCI_CONFIG_NAME)
|
if noCommit ~= true then uci:commit(UCI_CONFIG_NAME) end
|
||||||
return true
|
return true
|
||||||
end
|
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
|
--- Reset all settings to their default values
|
||||||
-- @string key The key to set.
|
-- @string key The key to set.
|
||||||
-- @treturn bool|nil True if everything went well, nil in case of error.
|
-- @treturn bool|nil True if everything went well, nil in case of error.
|
||||||
|
Loading…
Reference in New Issue
Block a user