fix padding last request
This commit is contained in:
parent
c220a09354
commit
77547e65aa
|
@ -617,7 +617,7 @@ Storage.prototype.storeActiveAddresses = function(walletId, addresses, cb) {
|
|||
Storage.prototype.getTxHistoryCache = function(walletId, from, to, cb) {
|
||||
var self = this;
|
||||
$.checkArgument(from >= 0);
|
||||
$.checkArgument(from<=to);
|
||||
$.checkArgument(from <= to);
|
||||
|
||||
self.db.collection(collections.CACHE).findOne({
|
||||
walletId: walletId,
|
||||
|
@ -631,10 +631,16 @@ Storage.prototype.getTxHistoryCache = function(walletId, from, to, cb) {
|
|||
// Reverse indexes
|
||||
var fwdIndex = result.totalItems - to;
|
||||
|
||||
if (fwdIndex < 0)
|
||||
return cb();
|
||||
if (fwdIndex < 0) {
|
||||
fwdIndex = 0;
|
||||
}
|
||||
|
||||
var end = result.totalItems - from;
|
||||
|
||||
// nothing to return
|
||||
if (end <=0)
|
||||
return cb(null, []);
|
||||
|
||||
var end = fwdIndex + to - from;
|
||||
|
||||
// Cache is OK.
|
||||
self.db.collection(collections.CACHE).findOne({
|
||||
|
@ -653,7 +659,7 @@ Storage.prototype.getTxHistoryCache = function(walletId, from, to, cb) {
|
|||
return !i;
|
||||
})) {
|
||||
// some items are not yet defined.
|
||||
return cb();
|
||||
return cb();
|
||||
}
|
||||
return cb(null, ret.reverse());
|
||||
});
|
||||
|
@ -740,7 +746,7 @@ Storage.prototype.storeTxHistoryCache = function(walletId, totalItems, firstPosi
|
|||
walletId: walletId,
|
||||
type: 'historyCache',
|
||||
key: null,
|
||||
history:h
|
||||
history: h
|
||||
}, {
|
||||
w: 1,
|
||||
upsert: true,
|
||||
|
|
|
@ -6334,6 +6334,7 @@ describe('Wallet service', function() {
|
|||
skip: i,
|
||||
limit: 5,
|
||||
}, function(err, txs, fromCache) {
|
||||
|
||||
should.not.exist(err);
|
||||
should.exist(txs);
|
||||
txs.length.should.equal(5);
|
||||
|
@ -6344,14 +6345,14 @@ describe('Wallet service', function() {
|
|||
});
|
||||
}, function() {
|
||||
// Ask more that cached.
|
||||
async.eachSeries(_.range(0, 210, 5), function(i, next) {
|
||||
async.eachSeries(_.range(0, 210, 7), function(i, next) {
|
||||
server.getTxHistory({
|
||||
skip: i,
|
||||
limit: 5,
|
||||
limit: 7,
|
||||
}, function(err, txs, fromCache) {
|
||||
should.not.exist(err);
|
||||
should.exist(txs);
|
||||
var s = h.slice(i, i + 5);
|
||||
var s = h.slice(i, i + 7);
|
||||
_.pluck(txs, 'txid').should.deep.equal(_.pluck(s, 'txid'));
|
||||
fromCache.should.equal(i >= Defaults.CONFIRMATIONS_TO_START_CACHING && i < 200);
|
||||
next();
|
||||
|
|
Loading…
Reference in New Issue