Small perf improvement in flattenDevice
This commit is contained in:
1 parent
cb183d1c56
commit
4ad416eccd
1 file changed
+5
-5
@@ -207,7 +207,7 @@ function processDeviceSort(sort) {
|
|||||||
function flattenDevice(device) {
|
function flattenDevice(device) {
|
||||||
function recursive(input, root, output, timestamp) {
|
function recursive(input, root, output, timestamp) {
|
||||||
for (let [name, tree] of Object.entries(input)) {
|
for (let [name, tree] of Object.entries(input)) {
|
||||||
if (root.length === 0)
|
if (!root)
|
||||||
if (name === "_lastInform") {
|
if (name === "_lastInform") {
|
||||||
output["Events.Inform"] = {
|
output["Events.Inform"] = {
|
||||||
value: [Date.parse(tree), "xsd:dateTime"],
|
value: [Date.parse(tree), "xsd:dateTime"],
|
||||||
@@ -309,7 +309,7 @@ function flattenDevice(device) {
|
|||||||
|
|
||||||
let childrenTimestamp = timestamp;
|
let childrenTimestamp = timestamp;
|
||||||
|
|
||||||
if (root.length === 0) childrenTimestamp = +(input["_timestamp"] || 1);
|
if (!root) childrenTimestamp = +(input["_timestamp"] || 1);
|
||||||
else if (+input["_timestamp"] > timestamp)
|
else if (+input["_timestamp"] > timestamp)
|
||||||
childrenTimestamp = +input["_timestamp"];
|
childrenTimestamp = +input["_timestamp"];
|
||||||
|
|
||||||
@@ -329,8 +329,8 @@ function flattenDevice(device) {
|
|||||||
attrs["writableTimestamp"] = childrenTimestamp;
|
attrs["writableTimestamp"] = childrenTimestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
let r = root.concat(name);
|
let r = root ? `${root}.${name}` : name;
|
||||||
output[r.join(".")] = attrs;
|
output[r] = attrs;
|
||||||
|
|
||||||
if (attrs["object"]) recursive(tree, r, output, childrenTimestamp);
|
if (attrs["object"]) recursive(tree, r, output, childrenTimestamp);
|
||||||
}
|
}
|
||||||
@@ -338,7 +338,7 @@ function flattenDevice(device) {
|
|||||||
|
|
||||||
const newDevice = {};
|
const newDevice = {};
|
||||||
const timestamp = new Date(device["_lastInform"] || 1).getTime();
|
const timestamp = new Date(device["_lastInform"] || 1).getTime();
|
||||||
recursive(device, [], newDevice, timestamp);
|
recursive(device, "", newDevice, timestamp);
|
||||||
return newDevice;
|
return newDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user