Yet another bug fix related to clearing aliases cache.

This commit is contained in:
Zaid Abdulla committed 2014-01-20 16:30:59 +03:00
1 parent 99c60b054e
commit e411d5e884
1 file changed
+5 -7
+5 -7
View File
@@ -75,7 +75,6 @@ updateDevice = (currentRequest, actions, callback) ->
updates["#{i[0]}._name"] = i[1] updates["#{i[0]}._name"] = i[1]
if actions.parameterNames? if actions.parameterNames?
newAliases = {} # possible new aliased parameters
for p in actions.parameterNames for p in actions.parameterNames
if OBJECT_REGEX.test(p[0]) if OBJECT_REGEX.test(p[0])
path = p[0] path = p[0]
@@ -89,7 +88,9 @@ updateDevice = (currentRequest, actions, callback) ->
updates["#{path}_timestamp"] = now updates["#{path}_timestamp"] = now
# Add parameter (sans any dot suffix) if has an alias # Add parameter (sans any dot suffix) if has an alias
newAliases[pp] = a if (a = parameters.getAlias(pp = path.slice(0, -1)))? if (a = parameters.getAlias(pp = path.slice(0, -1)))?
newAliases = {} if not newAliases?
newAliases[pp] = a
if actions.customCommands? if actions.customCommands?
for p in actions.customCommands for p in actions.customCommands
@@ -104,11 +105,8 @@ updateDevice = (currentRequest, actions, callback) ->
db.devicesCollection.update({'_id' : currentRequest.deviceId}, {'$set' : updates, '$unset' : deletes}, {}, (err, count) -> db.devicesCollection.update({'_id' : currentRequest.deviceId}, {'$set' : updates, '$unset' : deletes}, {}, (err, count) ->
throw err if err throw err if err
# Clear aliases cache if there's a new aliased parameter that has not been included in aliases cache # Clear aliases cache if there's a new aliased parameter that has not been included in aliases cache
if newAliases?.length if newAliases?
db.redisClient.get('aliases', (err, res) -> db.getAliases((aliases) ->
throw err if err
return if not res?
aliases = JSON.parse(res)
for p, a of newAliases for p, a of newAliases
if not aliases[a]? or p not in aliases[a] if not aliases[a]? or p not in aliases[a]
db.redisClient.del('aliases', (err, res) -> db.redisClient.del('aliases', (err, res) ->