Improved conflict handling of add/remove object configurations in presets

This commit is contained in:
Zaid Abdulla committed 2013-08-14 02:54:25 +03:00
1 parent 199adf5bcd
commit 3a42a297eb
1 file changed
+12 -4
+12 -4
View File
@@ -55,7 +55,7 @@ calculatePresetsHash = (presets, objects) ->
matchObject = (object, param) -> matchObject = (object, param) ->
return false if not object._keys? return false if not object._keys? or object._keys.length == 0
for k in object._keys for k in object._keys
v = common.matchType(param[k]._value, object[k]) v = common.matchType(param[k]._value, object[k])
if param[k]._value != v if param[k]._value != v
@@ -91,7 +91,7 @@ exports.assertPresets = (deviceId, presetsHash, callback) ->
if mongoQuery.test(device, p.precondition) if mongoQuery.test(device, p.precondition)
devicePresets.push(p) devicePresets.push(p)
configurations = accumulateConfigurations(devicePresets) configurations = accumulateConfigurations(devicePresets, objects)
now = Date.now() now = Date.now()
taskList = [] taskList = []
expiry = config.PRESETS_CACHE_DURATION expiry = config.PRESETS_CACHE_DURATION
@@ -186,7 +186,14 @@ exports.assertPresets = (deviceId, presetsHash, callback) ->
) )
accumulateConfigurations = (presets) -> getObjectHash = (object) ->
return object._id if not object._keys? or object._keys.length == 0
hash = ''
for k in object._keys
hash += "#{k}=#{object[k]}"
return hash
accumulateConfigurations = (presets, objects) ->
maxWeights = {} maxWeights = {}
configurations = {} configurations = {}
for p in presets for p in presets
@@ -195,7 +202,8 @@ accumulateConfigurations = (presets) ->
when 'add_tag', 'delete_tag' when 'add_tag', 'delete_tag'
"tag_#{c.tag}" "tag_#{c.tag}"
when 'add_object', 'delete_object' when 'add_object', 'delete_object'
"object_#{c.object}_#{c.object}" objectHash = getObjectHash(objects[c.object])
"object_#{c.name}_#{objectHash}"
when 'firmware' when 'firmware'
'firmware' 'firmware'
else else