From 231eec354429671fa43beace282002bbade25067 Mon Sep 17 00:00:00 2001 From: baldo Date: Sun, 19 Mar 2017 16:31:50 +0100 Subject: [PATCH] Fix: Avoid duplicates from different nodes.json files. Use only newest. --- server/services/monitoringService.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/server/services/monitoringService.js b/server/services/monitoringService.js index 8f9cbe5..8a032e1 100644 --- a/server/services/monitoringService.js +++ b/server/services/monitoringService.js @@ -465,11 +465,19 @@ angular.module('ffffng') // We do not parallelize here as the sqlite will start slowing down and blocking with too many // parallel queries. This has resulted in blocking other requests too and thus in a major slowdonw. - var nodes = _.flatMap(datas, function (data) { + var allNodes = _.flatMap(datas, function (data) { return data.nodes; }); + + // Get rid of duplicates from different nodes.json files. Always use the one with the newest + var sortedNodes = _.orderBy(allNodes, [function (node) { + return node.lastSeen.unix(); + }], ['desc']); + var uniqueNodes = _.uniqBy(sortedNodes, function (node) { + return node.mac; + }); async.eachSeries( - nodes, + uniqueNodes, function (nodeData, nodeCallback) { Logger.tag('monitoring', 'information-retrieval').debug('Importing: %s', nodeData.mac); @@ -509,7 +517,7 @@ angular.module('ffffng') return callback(err); } - markMissingNodesAsOffline(nodes, callback); + markMissingNodesAsOffline(uniqueNodes, callback); } ); });