Merge pull request #189 from cubedro/develop

Cleanup
This commit is contained in:
Marian OANCΞA 2015-06-10 05:54:45 +03:00
commit fbad4a5bca
2 changed files with 9 additions and 5 deletions

6
app.js
View File

@ -2,7 +2,7 @@ var _ = require('lodash');
var logger = require('./lib/utils/logger'); var logger = require('./lib/utils/logger');
var chalk = require('chalk'); var chalk = require('chalk');
var askedForHistoryTime = 0;
var WS_SECRET = process.env.WS_SECRET || "eth-net-stats-has-a-secret"; 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); console.info('API', 'CON', 'Open:', spark.address.ip);
spark.on('hello', function (data) spark.on('hello', function (data)
{ {
console.info('API', 'CON', 'Hello', data['id']); 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(); 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); console.info('API', 'HIS', 'Asked:', data.id, 'for history:', range.min, '-', range.max);
Nodes.askedForHistory(true); Nodes.askedForHistory(true);
askedForHistoryTime = _.now();
} }
} }
}); });

View File

@ -7,6 +7,7 @@ var Collection = function Collection()
this._items = []; this._items = [];
this._blockchain = new Blockchain(); this._blockchain = new Blockchain();
this._askedForHistory = false; this._askedForHistory = false;
this._askedForHistoryTime = 0;
this._debounced = null; this._debounced = null;
return this; return this;
@ -294,9 +295,14 @@ Collection.prototype.askedForHistory = function(set)
if( !_.isUndefined(set) ) if( !_.isUndefined(set) )
{ {
this._askedForHistory = 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; module.exports = Collection;