From 60cd4bdf73a258ad1dc7145db6286b878b7b00b5 Mon Sep 17 00:00:00 2001 From: cubedro Date: Wed, 10 Jun 2015 05:44:32 +0300 Subject: [PATCH] cleanup --- app.js | 6 ++---- lib/collection.js | 8 +++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app.js b/app.js index a26e09b..d6c0aef 100644 --- a/app.js +++ b/app.js @@ -2,7 +2,7 @@ var _ = require('lodash'); var logger = require('./lib/utils/logger'); var chalk = require('chalk'); -var askedForHistoryTime = 0; + var WS_SECRET = process.env.WS_SECRET || "eth-net-stats-has-a-secret"; @@ -69,7 +69,6 @@ api.on('connection', function (spark) { console.info('API', 'CON', 'Open:', spark.address.ip); - spark.on('hello', function (data) { console.info('API', 'CON', 'Hello', data['id']); @@ -299,7 +298,7 @@ api.on('connection', function (spark) } }); - if( Nodes.requiresUpdate(data.id) && (!Nodes.askedForHistory() || _.now() - askedForHistoryTime > 2*60*1000) ) + if( Nodes.requiresUpdate(data.id) && !Nodes.askedForHistory() ) { var range = Nodes.getHistory().getHistoryRequestRange(); @@ -307,7 +306,6 @@ api.on('connection', function (spark) console.info('API', 'HIS', 'Asked:', data.id, 'for history:', range.min, '-', range.max); Nodes.askedForHistory(true); - askedForHistoryTime = _.now(); } } }); diff --git a/lib/collection.js b/lib/collection.js index 59faedb..2079970 100644 --- a/lib/collection.js +++ b/lib/collection.js @@ -7,6 +7,7 @@ var Collection = function Collection() this._items = []; this._blockchain = new Blockchain(); this._askedForHistory = false; + this._askedForHistoryTime = 0; this._debounced = null; return this; @@ -294,9 +295,14 @@ Collection.prototype.askedForHistory = function(set) if( !_.isUndefined(set) ) { this._askedForHistory = set; + + if(set === true) + { + this._askedForHistoryTime = _.now(); + } } - return this._askedForHistory; + return (this._askedForHistory || _.now() - this._askedForHistoryTime < 2*60*1000); } module.exports = Collection;