Update backend lodash #2

pull/14/head
Peter Grassberger 6 years ago
parent 01779e3133
commit 3a506a7037
  1. 44
      lib/history.js
  2. 2
      package.json

@ -228,7 +228,7 @@ History.prototype._save = function(block)
{ {
this._items.unshift(block); this._items.unshift(block);
this._items = _.sortByOrder( this._items, 'height', false ); this._items = _.sortBy( this._items, 'height', false );
if(this._items.length > MAX_HISTORY) if(this._items.length > MAX_HISTORY)
{ {
@ -314,7 +314,7 @@ History.prototype.getNodePropagation = function(id)
_.fill(propagation, -1); _.fill(propagation, -1);
var sorted = _( this._items ) var sorted = _( this._items )
.sortByOrder( 'height', false ) .sortBy( 'height', false )
.slice( 0, MAX_PEER_PROPAGATION ) .slice( 0, MAX_PEER_PROPAGATION )
.forEach(function (item, key) .forEach(function (item, key)
{ {
@ -392,7 +392,7 @@ History.prototype.getBlockPropagation = function()
History.prototype.getUncleCount = function() History.prototype.getUncleCount = function()
{ {
var uncles = _( this._items ) var uncles = _( this._items )
.sortByOrder( 'height', false ) .sortBy( 'height', false )
// .filter(function (item) // .filter(function (item)
// { // {
// return item.block.trusted; // return item.block.trusted;
@ -420,7 +420,7 @@ History.prototype.getUncleCount = function()
History.prototype.getBlockTimes = function() History.prototype.getBlockTimes = function()
{ {
var blockTimes = _( this._items ) var blockTimes = _( this._items )
.sortByOrder( 'height', false ) .sortBy( 'height', false )
// .filter(function (item) // .filter(function (item)
// { // {
// return item.block.trusted; // return item.block.trusted;
@ -439,7 +439,7 @@ History.prototype.getBlockTimes = function()
History.prototype.getAvgBlocktime = function() History.prototype.getAvgBlocktime = function()
{ {
var blockTimes = _( this._items ) var blockTimes = _( this._items )
.sortByOrder( 'height', false ) .sortBy( 'height', false )
// .filter(function (item) // .filter(function (item)
// { // {
// return item.block.trusted; // return item.block.trusted;
@ -458,7 +458,7 @@ History.prototype.getAvgBlocktime = function()
History.prototype.getGasLimit = function() History.prototype.getGasLimit = function()
{ {
var gasLimitHistory = _( this._items ) var gasLimitHistory = _( this._items )
.sortByOrder( 'height', false ) .sortBy( 'height', false )
// .filter(function (item) // .filter(function (item)
// { // {
// return item.block.trusted; // return item.block.trusted;
@ -477,7 +477,7 @@ History.prototype.getGasLimit = function()
History.prototype.getDifficulty = function() History.prototype.getDifficulty = function()
{ {
var difficultyHistory = _( this._items ) var difficultyHistory = _( this._items )
.sortByOrder( 'height', false ) .sortBy( 'height', false )
.filter(function (item) .filter(function (item)
{ {
return item.block.trusted; return item.block.trusted;
@ -496,7 +496,7 @@ History.prototype.getDifficulty = function()
History.prototype.getTransactionsCount = function() History.prototype.getTransactionsCount = function()
{ {
var txCount = _( this._items ) var txCount = _( this._items )
.sortByOrder( 'height', false ) .sortBy( 'height', false )
.filter(function (item) .filter(function (item)
{ {
return item.block.trusted; return item.block.trusted;
@ -515,7 +515,7 @@ History.prototype.getTransactionsCount = function()
History.prototype.getGasSpending = function() History.prototype.getGasSpending = function()
{ {
var gasSpending = _( this._items ) var gasSpending = _( this._items )
.sortByOrder( 'height', false ) .sortBy( 'height', false )
.filter(function (item) .filter(function (item)
{ {
return item.block.trusted; return item.block.trusted;
@ -537,7 +537,7 @@ History.prototype.getAvgHashrate = function()
return 0; return 0;
var blocktimeHistory = _( this._items ) var blocktimeHistory = _( this._items )
.sortByOrder( 'height', false ) .sortBy( 'height', false )
// .filter(function (item) // .filter(function (item)
// { // {
// return item.block.trusted; // return item.block.trusted;
@ -557,7 +557,7 @@ History.prototype.getAvgHashrate = function()
History.prototype.getMinersCount = function() History.prototype.getMinersCount = function()
{ {
var miners = _( this._items ) var miners = _( this._items )
.sortByOrder( 'height', false ) .sortBy( 'height', false )
// .filter(function (item) // .filter(function (item)
// { // {
// return item.block.trusted; // return item.block.trusted;
@ -577,7 +577,7 @@ History.prototype.getMinersCount = function()
}); });
return _(minerCount) return _(minerCount)
.sortByOrder( 'blocks', false ) .sortBy( 'blocks', false )
.slice(0, 2) .slice(0, 2)
.value(); .value();
} }
@ -592,7 +592,7 @@ History.prototype.getCharts = function()
if(this._callback !== null) if(this._callback !== null)
{ {
var chartHistory = _( this._items ) var chartHistory = _( this._items )
.sortByOrder( 'height', false ) .sortBy( 'height', false )
// .filter(function (item) // .filter(function (item)
// { // {
// return item.block.trusted; // return item.block.trusted;
@ -615,15 +615,15 @@ History.prototype.getCharts = function()
.value(); .value();
this._callback(null, { this._callback(null, {
height : _.pluck( chartHistory, 'height' ), height : _.map( chartHistory, 'height' ),
blocktime : _.pluck( chartHistory, 'blocktime' ), blocktime : _.map( chartHistory, 'blocktime' ),
// avgBlocktime : _.sum(_.pluck( chartHistory, 'blocktime' )) / (chartHistory.length === 0 ? 1 : chartHistory.length), // avgBlocktime : _.sum(_.map( chartHistory, 'blocktime' )) / (chartHistory.length === 0 ? 1 : chartHistory.length),
avgBlocktime : this.getAvgBlocktime(), avgBlocktime : this.getAvgBlocktime(),
difficulty : _.pluck( chartHistory, 'difficulty' ), difficulty : _.map( chartHistory, 'difficulty' ),
uncles : _.pluck( chartHistory, 'uncles' ), uncles : _.map( chartHistory, 'uncles' ),
transactions : _.pluck( chartHistory, 'transactions' ), transactions : _.map( chartHistory, 'transactions' ),
gasSpending : _.pluck( chartHistory, 'gasSpending' ), gasSpending : _.map( chartHistory, 'gasSpending' ),
gasLimit : _.pluck( chartHistory, 'gasLimit' ), gasLimit : _.map( chartHistory, 'gasLimit' ),
miners : this.getMinersCount(), miners : this.getMinersCount(),
propagation : this.getBlockPropagation(), propagation : this.getBlockPropagation(),
uncleCount : this.getUncleCount(), uncleCount : this.getUncleCount(),
@ -643,7 +643,7 @@ History.prototype.getHistoryRequestRange = function()
if( this._items.length < 2 ) if( this._items.length < 2 )
return false; return false;
var blocks = _.pluck( this._items, 'height' ); var blocks = _.map( this._items, 'height' );
var best = _.max( blocks ); var best = _.max( blocks );
var range = _.range( _.max([ 0, best - MAX_HISTORY ]), best + 1); var range = _.range( _.max([ 0, best - MAX_HISTORY ]), best + 1);

@ -27,7 +27,7 @@
"grunt-contrib-jade": "^1.0.0", "grunt-contrib-jade": "^1.0.0",
"grunt-contrib-uglify": "^4.0.0", "grunt-contrib-uglify": "^4.0.0",
"jade": "^1.11.0", "jade": "^1.11.0",
"lodash": "3.10.1", "lodash": "4.17.11",
"primus": "^7.3.1", "primus": "^7.3.1",
"primus-emit": "^1.0.0", "primus-emit": "^1.0.0",
"primus-spark-latency": "^0.1.1", "primus-spark-latency": "^0.1.1",

Loading…
Cancel
Save