Optimize loadPath function
This commit is contained in:
1 parent
9dd6980da2
commit
f444ff753c
1 file changed
+20
-11
+20
-11
@@ -77,10 +77,11 @@ init = (deviceId, cwmpVersion, timeout, callback) ->
|
|||||||
|
|
||||||
|
|
||||||
loadParameters = (sessionContext, callback) ->
|
loadParameters = (sessionContext, callback) ->
|
||||||
if not sessionContext.toLoad?.length
|
if not sessionContext.toLoad?.size
|
||||||
return callback()
|
return callback()
|
||||||
|
|
||||||
db.fetchDevice(sessionContext.deviceId, sessionContext.timestamp, sessionContext.toLoad, (err, parameters, loaded) ->
|
toLoad = Array.from(sessionContext.toLoad.entries())
|
||||||
|
db.fetchDevice(sessionContext.deviceId, sessionContext.timestamp, toLoad, (err, parameters, loaded) ->
|
||||||
return callback(err) if err
|
return callback(err) if err
|
||||||
|
|
||||||
if not parameters?
|
if not parameters?
|
||||||
@@ -143,6 +144,9 @@ inform = (sessionContext, rpcReq, callback) ->
|
|||||||
params.push([['Events', e.replace(' ', '_')], timestamp,
|
params.push([['Events', e.replace(' ', '_')], timestamp,
|
||||||
{object: [timestamp, 0], writable: [timestamp, 0], value: [timestamp, [timestamp, 'xsd:dateTime']]}])
|
{object: [timestamp, 0], writable: [timestamp, 0], value: [timestamp, [timestamp, 'xsd:dateTime']]}])
|
||||||
|
|
||||||
|
# Preload DeviceID params
|
||||||
|
loadPath(sessionContext, ['DeviceID', '*'])
|
||||||
|
|
||||||
for p in params
|
for p in params
|
||||||
loadPath(sessionContext, p[0])
|
loadPath(sessionContext, p[0])
|
||||||
|
|
||||||
@@ -1225,8 +1229,10 @@ processDeclarations = (sessionContext, allDeclareTimestamps, allDeclareAttribute
|
|||||||
|
|
||||||
|
|
||||||
loadPath = (sessionContext, path, depth) ->
|
loadPath = (sessionContext, path, depth) ->
|
||||||
return true if sessionContext.new
|
depth = depth or (1 << path.length) - 1
|
||||||
depth ?= (1 << path.length) - 1
|
return true if sessionContext.new or not depth
|
||||||
|
|
||||||
|
sessionContext.toLoad ?= new Map()
|
||||||
|
|
||||||
# Trim trailing wildcards
|
# Trim trailing wildcards
|
||||||
trimWildcard = path.length
|
trimWildcard = path.length
|
||||||
@@ -1234,14 +1240,17 @@ loadPath = (sessionContext, path, depth) ->
|
|||||||
path = path.slice(0, trimWildcard) if trimWildcard < path.length
|
path = path.slice(0, trimWildcard) if trimWildcard < path.length
|
||||||
|
|
||||||
for i in [0..path.length] by 1
|
for i in [0..path.length] by 1
|
||||||
for sup in sessionContext.deviceData.paths.find(path.slice(0, i), true, false)
|
d = if i == path.length then 99 else i
|
||||||
v = sessionContext.deviceData.loaded.get(sup)
|
for sup in sessionContext.deviceData.paths.find(path.slice(0, i), true, false, d)
|
||||||
depth &= depth ^ sessionContext.deviceData.loaded.get(sup)
|
v = sessionContext.deviceData.loaded.get(sup) | sessionContext.toLoad.get(sup)
|
||||||
|
if sup.length > i
|
||||||
|
v &= (1 << i) - 1
|
||||||
|
depth &= depth ^ v
|
||||||
|
return true if depth == 0
|
||||||
|
|
||||||
return true if depth == 0
|
path = sessionContext.deviceData.paths.add(path)
|
||||||
|
depth |= sessionContext.toLoad.get(path)
|
||||||
sessionContext.toLoad ?= []
|
sessionContext.toLoad.set(path, depth)
|
||||||
sessionContext.toLoad.push([path, depth])
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user