Skip to content

Commit

Permalink
Gigantic performance improvemet
Browse files Browse the repository at this point in the history
... 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).
  • Loading branch information
typhoonsimon committed Mar 14, 2020
1 parent 56e3752 commit 917b9c6
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions lib/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,28 +435,33 @@ module.exports = {
},

get_last_txs_ajax: function(start, length, min, cb) {
Tx.countDocuments({'total': {$gte: min}}, function(err, count){
Tx.find({'total': {$gte: min}}).sort({blockindex: 'desc'}).skip(Number(start)).limit(Number(length)).exec(function(err, txs){
if (err) {
return cb(err);
} else {
return cb(txs, count);
}
});
lib.get_blockcount(function(blockcount) {
var blockFrom = blockcount - Number(start);
if (settings.index.last_txs != 0) {
blockcount = settings.index.last_txs;
}
var q = {$and: [{total: {$gt: Number(min)}}, {blockindex: {$lte: blockFrom}}]};
Tx.find(q).sort({blockindex: -1}).limit(Number(length)).exec(function(err, txs) {
if (err) {
return cb(err);
} else {
return cb(txs, blockcount);
}
});
});
},

get_address_txs_ajax: function(hash, start, length, cb) {
var totalCount = 0;
AddressTx.find({a_id: hash}).countDocuments({}, function(err, count){
AddressTx.find({a_id: hash}).count(function(err, count){
if(err) {
return cb(err);
} else {
totalCount = count;
AddressTx.aggregate([
{ $match: { a_id: hash } },
{ $match: { a_id: hash } },
{ $sort: {blockindex: -1} },
{ $skip: Number(start) },
{ $skip: Number(start) },
{
$group: {
_id: '',
Expand All @@ -474,7 +479,7 @@ module.exports = {
if (err) {
return cb(err);
} else {
AddressTx.find({a_id: hash}).sort({blockindex: 'desc'}).skip(Number(start)).limit(Number(length)).exec(function (err, address_tx) {
AddressTx.find({a_id: hash}).sort({blockindex: -1}).skip(Number(start)).limit(Number(length)).exec(function (err, address_tx) {
if (err) {
return cb(err);
} else {
Expand Down

0 comments on commit 917b9c6

Please sign in to comment.