Fix bugs related to tracking changes
This commit is contained in:
1 parent
7b0ea61596
commit
1bbef345e0
2 files changed
+24
-34
No files matched your search
+19
-29
@@ -170,16 +170,16 @@ function unpack(deviceData, path, revision) {
|
||||
|
||||
function clear(deviceData, path, timestamp, attributes) {
|
||||
for (let p of deviceData.paths.all(path, timestamp ? 99 : 0)) {
|
||||
for (let k in deviceData.trackers.get(p))
|
||||
deviceData.changes.add(k);
|
||||
|
||||
let t = deviceData.timestamps.get(p);
|
||||
if (!t)
|
||||
continue;
|
||||
|
||||
let changeFlags = 0;
|
||||
|
||||
if (!(timestamp <= t)) {
|
||||
deviceData.timestamps.delete(p);
|
||||
deviceData.attributes.delete(p);
|
||||
changeFlags |= 3;
|
||||
} else if (t && attributes) {
|
||||
let currentAttributes = deviceData.attributes.get(p);
|
||||
if (currentAttributes) {
|
||||
@@ -190,8 +190,6 @@ function clear(deviceData, path, timestamp, attributes) {
|
||||
if (!newAttrs)
|
||||
newAttrs = JSON.parse(JSON.stringify(currentAttributes));
|
||||
delete newAttrs[attrName];
|
||||
changeFlags |= CHANGE_FLAGS[attrName];
|
||||
changeFlags |= CHANGE_FLAGS[attrName] << 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,14 +197,6 @@ function clear(deviceData, path, timestamp, attributes) {
|
||||
deviceData.attributes.set(p, newAttrs);
|
||||
}
|
||||
}
|
||||
|
||||
if (changeFlags)
|
||||
for (let sup of deviceData.paths.superset(p)) {
|
||||
let c = deviceData.trackers.get(sup);
|
||||
for (let k in c)
|
||||
if (c[k] & changeFlags)
|
||||
deviceData.changes.add(k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,8 +218,6 @@ function compareEquality(a, b) {
|
||||
function set(deviceData, path, timestamp, attributes, toClear) {
|
||||
path = deviceData.paths.add(path);
|
||||
|
||||
let changeFlags = 0;
|
||||
|
||||
let currentTimestamp = deviceData.timestamps.get(path);
|
||||
|
||||
let currentAttributes;
|
||||
@@ -249,6 +237,8 @@ function set(deviceData, path, timestamp, attributes, toClear) {
|
||||
attributes.value = [attributes.object[0]];
|
||||
|
||||
if (currentAttributes) {
|
||||
let changeFlags = 0;
|
||||
|
||||
for (let attrName in attributes) {
|
||||
timestamp = Math.max(timestamp, attributes[attrName][0]);
|
||||
if (attrName in currentAttributes) {
|
||||
@@ -267,7 +257,8 @@ function set(deviceData, path, timestamp, attributes, toClear) {
|
||||
}
|
||||
|
||||
if (Object.keys(attributes).length) {
|
||||
if (attributes.object && attributes.object[1] === 0) {
|
||||
if (attributes.object && currentAttributes.object &&
|
||||
attributes.object[1] !== currentAttributes.object[1]) {
|
||||
toClear = toClear || [];
|
||||
toClear.push([path.concat('*'), attributes.object[0]]);
|
||||
}
|
||||
@@ -279,15 +270,24 @@ function set(deviceData, path, timestamp, attributes, toClear) {
|
||||
}
|
||||
|
||||
if (timestamp > currentTimestamp) {
|
||||
changeFlags |= 1;
|
||||
deviceData.timestamps.set(path, timestamp);
|
||||
|
||||
if (path.length > 1)
|
||||
toClear = set(deviceData, path.slice(0, path.length - 1), timestamp,
|
||||
{object: [timestamp, 1]}, toClear);
|
||||
}
|
||||
|
||||
if (changeFlags)
|
||||
for (let sup of deviceData.paths.superset(path)) {
|
||||
let c = deviceData.trackers.get(sup);
|
||||
for (let k in c)
|
||||
if (c[k] & changeFlags) {
|
||||
deviceData.changes.add(k);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!(timestamp <= currentTimestamp)) {
|
||||
changeFlags |= 2;
|
||||
deviceData.timestamps.set(path, timestamp);
|
||||
deviceData.attributes.set(path, attributes);
|
||||
|
||||
@@ -300,11 +300,9 @@ function set(deviceData, path, timestamp, attributes, toClear) {
|
||||
}
|
||||
}
|
||||
else if (!(timestamp <= currentTimestamp)) {
|
||||
changeFlags |= 1;
|
||||
deviceData.timestamps.set(path, timestamp);
|
||||
|
||||
if (currentAttributes) {
|
||||
changeFlags |= 2;
|
||||
deviceData.attributes.delete(path);
|
||||
toClear = toClear || [];
|
||||
toClear.push([path, timestamp]);
|
||||
@@ -321,14 +319,6 @@ function set(deviceData, path, timestamp, attributes, toClear) {
|
||||
}
|
||||
}
|
||||
|
||||
if (changeFlags)
|
||||
for (let sup of deviceData.paths.superset(path)) {
|
||||
let c = deviceData.trackers.get(sup);
|
||||
for (let k in c)
|
||||
if (c[k] & changeFlags)
|
||||
deviceData.changes.add(k);
|
||||
}
|
||||
|
||||
return toClear;
|
||||
}
|
||||
|
||||
@@ -344,11 +334,11 @@ function track(deviceData, path, marker, timestamp, attributeTimestamps, exist,
|
||||
f |= 2;
|
||||
|
||||
if (attributeTimestamps)
|
||||
for (let attrName in attributeTimestamps)
|
||||
for (let attrName of attributeTimestamps)
|
||||
f |= CHANGE_FLAGS[attrName];
|
||||
|
||||
if (attributeValues)
|
||||
for (let attrName in attributeValues)
|
||||
for (let attrName of attributeValues)
|
||||
f |= CHANGE_FLAGS[attrName] << 1;
|
||||
|
||||
let cur = deviceData.trackers.get(path);
|
||||
|
||||
+5
-5
@@ -442,10 +442,6 @@ rpcRequest = (sessionData, _declarations, callback) ->
|
||||
)
|
||||
)
|
||||
|
||||
if sessionData.deviceData.changes.has('prerequisite')
|
||||
delete sessionData.syncState
|
||||
device.clearTrackers(sessionData.deviceData, 'prerequisite')
|
||||
|
||||
if _declarations?.length
|
||||
delete sessionData.syncState
|
||||
sessionData.declarations[0] ?= []
|
||||
@@ -493,6 +489,11 @@ rpcRequest = (sessionData, _declarations, callback) ->
|
||||
if not provisions
|
||||
sessionData.rpcRequest = generateGetRpcRequest(sessionData)
|
||||
if not sessionData.rpcRequest
|
||||
if sessionData.deviceData.changes.has('prerequisite')
|
||||
delete sessionData.syncState
|
||||
device.clearTrackers(sessionData.deviceData, 'prerequisite')
|
||||
return rpcRequest(sessionData, null, callback)
|
||||
|
||||
provisions = generateSetVirtualParameterProvisions(sessionData, sessionData.syncState.virtualParameterDeclarations[inception])
|
||||
if not provisions
|
||||
sessionData.rpcRequest = generateSetRpcRequest(sessionData)
|
||||
@@ -814,7 +815,6 @@ processDeclarations = (sessionData, allDeclareTimestamps, allDeclareAttributeTim
|
||||
for attrName of attrs
|
||||
declareAttributeValues[attrName] = attrs[attrName]
|
||||
|
||||
aaa = (if currentPath[0] != '*' then currentPath[0] else leafParam[0])
|
||||
switch (if currentPath[0] != '*' then currentPath[0] else leafParam[0])
|
||||
when 'Reboot'
|
||||
if currentPath.length == 1
|
||||
|
||||
Reference in new issue
Block a user