skip doing 2 queries if all addresses are active (only in new imported wallets, mainly)

This commit is contained in:
Matias Alejo Garcia 2017-11-02 13:35:39 -03:00
parent 1db21481d6
commit 23278a06fb
No known key found for this signature in database
GPG Key ID: 02470DB551277AB3
1 changed files with 11 additions and 2 deletions

View File

@ -1311,6 +1311,12 @@ WalletService.prototype._getBalanceOneStep = function(opts, cb) {
self.storage.fetchAddresses(self.walletId, function(err, addresses) { self.storage.fetchAddresses(self.walletId, function(err, addresses) {
if (err) return cb(err); if (err) return cb(err);
if (addresses.length == opts.alreadyQueriedLength) {
log.info('Query Skipped, all active addresses');
return cb(null,null, true);
}
self._getBalanceFromAddresses({ self._getBalanceFromAddresses({
coin: opts.coin, coin: opts.coin,
addresses: addresses addresses: addresses
@ -1435,13 +1441,16 @@ WalletService.prototype.getBalance = function(opts, cb, i) {
setTimeout(function() { setTimeout(function() {
log.debug('Running full balance query'); log.debug('Running full balance query');
self._getBalanceOneStep(opts, function(err, fullBalance) { opts.alreadyQueriedLength = activeAddresses.length;
self._getBalanceOneStep(opts, function(err, fullBalance, skipped) {
if (err) return; if (err) return;
if (!_.isEqual(partialBalance, fullBalance)) { if (!skipped && !_.isEqual(partialBalance, fullBalance)) {
log.info('Balance in active addresses differs from final balance'); log.info('Balance in active addresses differs from final balance');
self._notify('BalanceUpdated', fullBalance, { self._notify('BalanceUpdated', fullBalance, {
isGlobal: true isGlobal: true
}); });
} else if (skipped) {
return;
} else { } else {
// updates cache // updates cache
twoStepCache.lastEmpty = now; twoStepCache.lastEmpty = now;