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) {
|
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,
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue