diff --git a/lib/database.js b/lib/database.js index f2f8afdbf..298278d53 100644 --- a/lib/database.js +++ b/lib/database.js @@ -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: '', @@ -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 {