This commit is contained in:
cubedro 2015-06-10 05:44:32 +03:00
parent a50a3b29f9
commit 60cd4bdf73
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 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();
}
}
});

View File

@ -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;