From a0524ce41bc7ac203291f5d96fc273b190918bba Mon Sep 17 00:00:00 2001 From: Cryptkeeper Date: Fri, 18 Dec 2015 02:43:44 -0600 Subject: [PATCH] Ignore data for networks that don't exist in config.json --- assets/js/site.js | 1 + lib/util.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/assets/js/site.js b/assets/js/site.js index 3d17a73..a2e6282 100644 --- a/assets/js/site.js +++ b/assets/js/site.js @@ -42,6 +42,7 @@ var bigChartOptions = { }, yaxis: { show: true, + tickSize: 1000, tickLength: 10, tickFormatter: function(value) { return formatNumber(value); diff --git a/lib/util.js b/lib/util.js index 2f7f5ae..f9b96fd 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1,10 +1,34 @@ +var config = require('../config.json'); + +// Checks if we have a server in config.json with the IP. +function serverWithIpExists(ip) { + for (var i = 0; i < config.servers.length; i++) { + var entry = config.servers[i]; + + if (entry.ip === ip) { + return true; + } + } + + return false; +} + // This method is a monstrosity. // Since we loaded ALL pings from the database, we need to filter out the pings so each entry is a minute apart. // This is done by iterating over the list, since the time between each ping can be completely arbitrary. function trimUselessPings(data) { var keys = Object.keys(data); + var keysToRemove = []; + for (var i = 0; i < keys.length; i++) { + // Don't bother we servers we deleted from config.json + if (!serverWithIpExists(keys[i])) { + keysToRemove.push(keys[i]); + + continue; + } + var listing = data[keys[i]]; var lastTimestamp = 0; @@ -30,6 +54,11 @@ function trimUselessPings(data) { data[keys[i]] = filteredListing; } + + // Delete data for any networks we don't care about anymore. + for (var i = 0; i < keysToRemove.length; i++) { + delete data[entry]; + } } exports.getCurrentTimeMs = function() {