From 6b8458d8656eb836811b09cf7606cff58b5a84be Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Mon, 28 Dec 2015 04:38:51 +0000 Subject: Minor cleanup for efficiency --- provisioning-model.lua | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/provisioning-model.lua b/provisioning-model.lua index 8f57e9a..bb5142f 100644 --- a/provisioning-model.lua +++ b/provisioning-model.lua @@ -1212,16 +1212,16 @@ mymodule.update_group = function(self, group, action, create) if not tmp or #tmp == 0 then success = false errtxt = "Group does not exist" - end - - -- Find all devices that have this group so we can notify on a param default value change - sql = "SELECT d2t.device_id ".. - "FROM (devices_to_classes d2t JOIN provisioning_classes t USING(class_id) JOIN classes_to_param_groups t2g USING (class_id)) ".. - "WHERE t2g.group_id='"..provdb.escape(group.value.group_id.value).."'" - devices = getselectresponse(sql) - -- Make sure the current params are saved for each device - for i,d in ipairs(devices) do - if not saved_device_params[d.device_id] then get_device_params(d.device_id) end + else + -- Find all devices that have this group so we can notify on a param default value change + sql = "SELECT d2t.device_id ".. + "FROM (devices_to_classes d2t JOIN provisioning_classes t USING(class_id) JOIN classes_to_param_groups t2g USING (class_id)) ".. + "WHERE t2g.group_id='"..provdb.escape(group.value.group_id.value).."'" + devices = getselectresponse(sql) + -- Make sure the current params are saved for each device + for i,d in ipairs(devices) do + if not saved_device_params[d.device_id] then get_device_params(d.device_id) end + end end end if success then @@ -1415,16 +1415,16 @@ mymodule.update_param = function(self, param, action, create) if not tmp or #tmp == 0 then success = false errtxt = "Param does not exist" - end - - -- Find all devices that have this param so we can notify on a param default value change - sql = "SELECT d2t.device_id FROM (devices_to_classes d2t JOIN provisioning_classes t USING(class_id) JOIN classes_to_param_groups t2g USING (class_id) ".. - "JOIN provisioning_groups g USING(group_id) JOIN param_groups_to_params g2p USING(group_id))".. - "WHERE g2p.param_id='"..provdb.escape(param.value.param_id.value).."'" - devices = getselectresponse(sql) - -- Make sure the current params are saved for each device - for i,d in ipairs(devices) do - if not saved_device_params[d.device_id] then get_device_params(d.device_id) end + else + -- Find all devices that have this param so we can notify on a param default value change + sql = "SELECT d2t.device_id FROM (devices_to_classes d2t JOIN provisioning_classes t USING(class_id) JOIN classes_to_param_groups t2g USING (class_id) ".. + "JOIN provisioning_groups g USING(group_id) JOIN param_groups_to_params g2p USING(group_id))".. + "WHERE g2p.param_id='"..provdb.escape(param.value.param_id.value).."'" + devices = getselectresponse(sql) + -- Make sure the current params are saved for each device + for i,d in ipairs(devices) do + if not saved_device_params[d.device_id] then get_device_params(d.device_id) end + end end end if success then -- cgit v1.2.3