fix padding last request

This commit is contained in:
Matias Alejo Garcia 2016-07-29 11:51:45 -03:00
parent c220a09354
commit 77547e65aa
No known key found for this signature in database
GPG Key ID: 02470DB551277AB3
2 changed files with 16 additions and 9 deletions

View File

@ -617,7 +617,7 @@ Storage.prototype.storeActiveAddresses = function(walletId, addresses, cb) {
Storage.prototype.getTxHistoryCache = function(walletId, from, to, cb) { Storage.prototype.getTxHistoryCache = function(walletId, from, to, cb) {
var self = this; var self = this;
$.checkArgument(from >= 0); $.checkArgument(from >= 0);
$.checkArgument(from<=to); $.checkArgument(from <= to);
self.db.collection(collections.CACHE).findOne({ self.db.collection(collections.CACHE).findOne({
walletId: walletId, walletId: walletId,
@ -631,10 +631,16 @@ Storage.prototype.getTxHistoryCache = function(walletId, from, to, cb) {
// Reverse indexes // Reverse indexes
var fwdIndex = result.totalItems - to; var fwdIndex = result.totalItems - to;
if (fwdIndex < 0) if (fwdIndex < 0) {
return cb(); fwdIndex = 0;
}
var end = result.totalItems - from;
// nothing to return
if (end <=0)
return cb(null, []);
var end = fwdIndex + to - from;
// Cache is OK. // Cache is OK.
self.db.collection(collections.CACHE).findOne({ self.db.collection(collections.CACHE).findOne({
@ -740,7 +746,7 @@ Storage.prototype.storeTxHistoryCache = function(walletId, totalItems, firstPosi
walletId: walletId, walletId: walletId,
type: 'historyCache', type: 'historyCache',
key: null, key: null,
history:h history: h
}, { }, {
w: 1, w: 1,
upsert: true, upsert: true,

View File

@ -6334,6 +6334,7 @@ describe('Wallet service', function() {
skip: i, skip: i,
limit: 5, limit: 5,
}, function(err, txs, fromCache) { }, function(err, txs, fromCache) {
should.not.exist(err); should.not.exist(err);
should.exist(txs); should.exist(txs);
txs.length.should.equal(5); txs.length.should.equal(5);
@ -6344,14 +6345,14 @@ describe('Wallet service', function() {
}); });
}, function() { }, function() {
// Ask more that cached. // Ask more that cached.
async.eachSeries(_.range(0, 210, 5), function(i, next) { async.eachSeries(_.range(0, 210, 7), function(i, next) {
server.getTxHistory({ server.getTxHistory({
skip: i, skip: i,
limit: 5, limit: 7,
}, function(err, txs, fromCache) { }, function(err, txs, fromCache) {
should.not.exist(err); should.not.exist(err);
should.exist(txs); 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')); _.pluck(txs, 'txid').should.deep.equal(_.pluck(s, 'txid'));
fromCache.should.equal(i >= Defaults.CONFIRMATIONS_TO_START_CACHING && i < 200); fromCache.should.equal(i >= Defaults.CONFIRMATIONS_TO_START_CACHING && i < 200);
next(); next();