diff --git a/lib/cwmp.coffee b/lib/cwmp.coffee index b576dab..05e48c3 100644 --- a/lib/cwmp.coffee +++ b/lib/cwmp.coffee @@ -139,14 +139,9 @@ inform = (currentRequest, cwmpRequest) -> actions.set._lastBoot = now if '1 BOOT' in cwmpRequest.methodRequest.event actions.set._lastBootstrap = lastBootstrap = now if '0 BOOTSTRAP' in cwmpRequest.methodRequest.event - db.redisClient.get("#{currentRequest.deviceId}_inform_hash", (err, res) -> + db.redisClient.get("#{currentRequest.deviceId}_inform_hash", (err, oldInformHash) -> throw err if err - if not res? - db.redisClient.setex("#{currentRequest.deviceId}_inform_hash", config.PRESETS_CACHE_DURATION, informHash, (err, res) -> - throw err if err - ) - updateAndRespond = () -> updateDevice(currentRequest, actions, (err) -> throw err if err @@ -154,9 +149,13 @@ inform = (currentRequest, cwmpRequest) -> writeResponse(currentRequest, res) ) - if res == informHash + if oldInformHash == informHash and not lastBootstrap? return updateAndRespond() + db.redisClient.setex("#{currentRequest.deviceId}_inform_hash", config.PRESETS_CACHE_DURATION, informHash, (err, res) -> + throw err if err + ) + # populate projection and parameterStructure parameterStructure = {} projection = {} @@ -202,6 +201,12 @@ inform = (currentRequest, cwmpRequest) -> actions.deletedObjects ?= [] actions.deletedObjects.push("_customCommands.#{cmd}") + # clear presets hash if parameters are potentially modified + if _tasks.length > 0 + db.redisClient.del("#{currentRequest.deviceId}_presets_hash", (err) -> + throw err if err + ) + apiFunctions.insertTasks(_tasks, {}, () -> updateAndRespond() )