Skip to content

Commit 917b9c6

Browse files
authored
Gigantic performance improvemet
... over large chains. Added indexes and brought back last_txs setting (set to 0 will display the whole chain in the index, but without sacrificing server or mongo performance).
1 parent 56e3752 commit 917b9c6

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

lib/database.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -435,28 +435,33 @@ module.exports = {
435435
},
436436

437437
get_last_txs_ajax: function(start, length, min, cb) {
438-
Tx.countDocuments({'total': {$gte: min}}, function(err, count){
439-
Tx.find({'total': {$gte: min}}).sort({blockindex: 'desc'}).skip(Number(start)).limit(Number(length)).exec(function(err, txs){
440-
if (err) {
441-
return cb(err);
442-
} else {
443-
return cb(txs, count);
444-
}
445-
});
438+
lib.get_blockcount(function(blockcount) {
439+
var blockFrom = blockcount - Number(start);
440+
if (settings.index.last_txs != 0) {
441+
blockcount = settings.index.last_txs;
442+
}
443+
var q = {$and: [{total: {$gt: Number(min)}}, {blockindex: {$lte: blockFrom}}]};
444+
Tx.find(q).sort({blockindex: -1}).limit(Number(length)).exec(function(err, txs) {
445+
if (err) {
446+
return cb(err);
447+
} else {
448+
return cb(txs, blockcount);
449+
}
450+
});
446451
});
447452
},
448453

449454
get_address_txs_ajax: function(hash, start, length, cb) {
450455
var totalCount = 0;
451-
AddressTx.find({a_id: hash}).countDocuments({}, function(err, count){
456+
AddressTx.find({a_id: hash}).count(function(err, count){
452457
if(err) {
453458
return cb(err);
454459
} else {
455460
totalCount = count;
456461
AddressTx.aggregate([
457-
{ $match: { a_id: hash } },
462+
{ $match: { a_id: hash } },
458463
{ $sort: {blockindex: -1} },
459-
{ $skip: Number(start) },
464+
{ $skip: Number(start) },
460465
{
461466
$group: {
462467
_id: '',
@@ -474,7 +479,7 @@ module.exports = {
474479
if (err) {
475480
return cb(err);
476481
} else {
477-
AddressTx.find({a_id: hash}).sort({blockindex: 'desc'}).skip(Number(start)).limit(Number(length)).exec(function (err, address_tx) {
482+
AddressTx.find({a_id: hash}).sort({blockindex: -1}).skip(Number(start)).limit(Number(length)).exec(function (err, address_tx) {
478483
if (err) {
479484
return cb(err);
480485
} else {

0 commit comments

Comments
 (0)