Improve paramter set and load routines
This commit is contained in:
1 parent
de1a62b481
commit
739d215a92
4 files changed
+282
-225
No files matched your search
+102
-85
@@ -226,26 +226,6 @@ function unpack(deviceData, path, revision) {
|
||||
}
|
||||
|
||||
|
||||
function invalidateSuperset(deviceData, path, attributes) {
|
||||
let depth = 0;
|
||||
if (attributes.exist != null)
|
||||
depth = 99;
|
||||
|
||||
for (let sup of deviceData.paths.superset(path, 99)) {
|
||||
if (sup.wildcard == path.wildcard && sup.length == path.length)
|
||||
continue;
|
||||
|
||||
for (let attrName in deviceData.timestamps) {
|
||||
let t = deviceData.timestamps[attrName].get(sup);
|
||||
if (t <= attributes[attrName] || t <= attributes.exist) {
|
||||
deviceData.timestamps[attrName].delete(sup);
|
||||
deviceData.values[attrName].delete(sup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function normalizeAttributes(timestamps, values) {
|
||||
if ('value' in values && timestamps.value >= (timestamps.object || 0)) {
|
||||
values.object = 0;
|
||||
@@ -274,97 +254,132 @@ function normalizeAttributes(timestamps, values) {
|
||||
}
|
||||
|
||||
|
||||
function set(deviceData, path, timestamps, values) {
|
||||
function clear(deviceData, path, timestamps, toClear) {
|
||||
if (!toClear)
|
||||
toClear = new Map();
|
||||
|
||||
// Clear redundant subsets and deleted params
|
||||
for (let sub of deviceData.paths.subset(path)) {
|
||||
if (path.wildcard == sub.wildcard)
|
||||
continue;
|
||||
|
||||
if (deviceData.values.exist.has(sub)) {
|
||||
let existTimestamp = deviceData.timestamps.exist.get(sub);
|
||||
for (let attrName in timestamps) {
|
||||
if (timestamps[attrName] > existTimestamp) {
|
||||
let inv = toClear.get(sub);
|
||||
if (inv == null)
|
||||
toClear.set(sub, inv = {});
|
||||
for (let attrName in deviceData.timestamps) {
|
||||
inv[attrName] = timestamps[attrName];
|
||||
deviceData.timestamps[attrName].delete(sub);
|
||||
deviceData.values[attrName].delete(sub);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (timestamps[attrName] > deviceData.timestamps[attrName].get(sub)) {
|
||||
if (deviceData.values[attrName].has(sub)) {
|
||||
let inv = toClear.get(sub);
|
||||
if (inv == null)
|
||||
toClear.set(sub, inv = {});
|
||||
inv[attrName] = timestamps[attrName];
|
||||
deviceData.values[attrName].delete(sub);
|
||||
}
|
||||
deviceData.timestamps[attrName].set(sub, timestamps[attrName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (let attrName in timestamps) {
|
||||
if (attrName == 'exist') {
|
||||
for (let an in deviceData.timestamps)
|
||||
if (timestamps[attrName] > deviceData.timestamps[an].get(sub))
|
||||
deviceData.timestamps[an].delete(sub);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (timestamps[attrName] > deviceData.timestamps[attrName].get(sub))
|
||||
deviceData.timestamps[attrName].delete(sub);
|
||||
}
|
||||
}
|
||||
}
|
||||
return toClear;
|
||||
}
|
||||
|
||||
|
||||
function clearSupersets(deviceData, path, timestamps) {
|
||||
let depth = 0;
|
||||
if (timestamps.exist != null)
|
||||
depth = 99;
|
||||
|
||||
for (let sup of deviceData.paths.superset(path, 99)) {
|
||||
if (sup.wildcard == path.wildcard && sup.length == path.length)
|
||||
continue;
|
||||
|
||||
for (let attrName in deviceData.timestamps) {
|
||||
let t = deviceData.timestamps[attrName].get(sup);
|
||||
if (t <= timestamps[attrName] || t <= timestamps.exist) {
|
||||
deviceData.timestamps[attrName].delete(sup);
|
||||
deviceData.values[attrName].delete(sup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function set(deviceData, path, timestamps, values, toClear) {
|
||||
path = deviceData.paths.add(path);
|
||||
if (path.wildcard || values == null)
|
||||
values = {};
|
||||
|
||||
let toInvalidate = new Map();
|
||||
|
||||
if (values.exist) {
|
||||
normalizeAttributes(timestamps, values);
|
||||
if (timestamps.exist && path.length > 1) {
|
||||
set(deviceData, path.slice(0, path.length - 1),
|
||||
if (timestamps.exist && path.length > 1)
|
||||
toClear = set(deviceData, path.slice(0, path.length - 1),
|
||||
{exist: timestamps.exist, object: timestamps.exist},
|
||||
{exist: 1, object: 1});
|
||||
}
|
||||
{exist: 1, object: 1},
|
||||
toClear);
|
||||
else if (!toClear)
|
||||
toClear = new Map();
|
||||
|
||||
// Clear attribute patterns
|
||||
for (let attrName in timestamps) {
|
||||
if (deviceData.values[attrName].has(path) != (attrName in values)) {
|
||||
let inv = toInvalidate.get(path);
|
||||
let inv = toClear.get(path);
|
||||
if (inv == null)
|
||||
toInvalidate.set(path, inv = {});
|
||||
toClear.set(path, inv = {});
|
||||
inv[attrName] = timestamps[attrName];
|
||||
if (!(attrName in values))
|
||||
deviceData.values[attrName].delete(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Clear redundant timestamps
|
||||
let current = inferTimestamps(deviceData, path);
|
||||
for (let c in timestamps)
|
||||
if (timestamps[c] <= current[c])
|
||||
delete timestamps[c];
|
||||
else if (c != 'exist' &&
|
||||
(timestamps[c] <= timestamps.exist || timestamps[c] <= current.exist))
|
||||
delete timetamps[c];
|
||||
|
||||
// Clear redundant subsets and deleted params
|
||||
for (let sub of deviceData.paths.subset(path)) {
|
||||
if (path.wildcard == sub.wildcard)
|
||||
continue;
|
||||
|
||||
if (deviceData.values.exist.has(sub)) {
|
||||
let existTimestamp = deviceData.timestamps.exist.get(sub);
|
||||
for (let attrName in timestamps) {
|
||||
if (timestamps[attrName] > existTimestamp) {
|
||||
let inv = toInvalidate.get(sub);
|
||||
if (inv == null)
|
||||
toInvalidate.set(sub, inv = {});
|
||||
for (let attrName in deviceData.timestamps) {
|
||||
inv[attrName] = timestamps[attrName];
|
||||
deviceData.timestamps[attrName].delete(sub);
|
||||
deviceData.values[attrName].delete(sub);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (timestamps[attrName] > deviceData.timestamps[attrName].get(sub))
|
||||
if (deviceData.values[attrName].has(sub)) {
|
||||
let inv = toInvalidate.get(sub);
|
||||
if (inv == null)
|
||||
toInvalidate.set(sub, inv = {});
|
||||
inv[attrName] = timestamps[attrName];
|
||||
deviceData.values[attrName].delete(sub);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (let attrName in timestamps) {
|
||||
if (attrName == 'exist') {
|
||||
for (let an in deviceData.timestamps)
|
||||
if (timestamps[attrName] > deviceData.timestamps[an].get(sub))
|
||||
deviceData.timestamps[an].delete(sub);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (timestamps[attrName] > deviceData.timestamps[attrName].get(sub))
|
||||
deviceData.timestamps[attrName].delete(sub);
|
||||
}
|
||||
}
|
||||
for (let attrName in timestamps) {
|
||||
deviceData.timestamps[attrName].set(path, timestamps[attrName]);
|
||||
if (attrName in values)
|
||||
deviceData.values[attrName].set(path, values[attrName]);
|
||||
}
|
||||
|
||||
return toClear;
|
||||
}
|
||||
|
||||
toInvalidate.forEach(function(a, p) {
|
||||
invalidateSuperset(deviceData, p, a);
|
||||
});
|
||||
// Clear redundant timestamps
|
||||
let current = inferTimestamps(deviceData, path);
|
||||
for (let c in timestamps)
|
||||
if (timestamps[c] <= current[c])
|
||||
delete timestamps[c];
|
||||
else if (c != 'exist' &&
|
||||
(timestamps[c] <= timestamps.exist || timestamps[c] <= current.exist))
|
||||
delete timetamps[c];
|
||||
|
||||
for (let attrName in timestamps) {
|
||||
deviceData.timestamps[attrName].set(path, timestamps[attrName]);
|
||||
if (attrName in values)
|
||||
deviceData.values[attrName].set(path, values[attrName]);
|
||||
}
|
||||
|
||||
return clear(deviceData, path, timestamps, toClear);
|
||||
}
|
||||
|
||||
|
||||
@@ -373,3 +388,5 @@ exports.getAliasDeclarations = getAliasDeclarations;
|
||||
exports.inferTimestamps = inferTimestamps;
|
||||
exports.unpack = unpack;
|
||||
exports.set = set;
|
||||
exports.clear = clear;
|
||||
exports.clearSupersets = clearSupersets
|
||||
Reference in new issue
Block a user