skip doing 2 queries if all addresses are active (only in new imported wallets, mainly)
This commit is contained in:
parent
1db21481d6
commit
23278a06fb
|
@ -1311,6 +1311,12 @@ WalletService.prototype._getBalanceOneStep = function(opts, cb) {
|
|||
|
||||
self.storage.fetchAddresses(self.walletId, function(err, addresses) {
|
||||
if (err) return cb(err);
|
||||
|
||||
if (addresses.length == opts.alreadyQueriedLength) {
|
||||
log.info('Query Skipped, all active addresses');
|
||||
return cb(null,null, true);
|
||||
}
|
||||
|
||||
self._getBalanceFromAddresses({
|
||||
coin: opts.coin,
|
||||
addresses: addresses
|
||||
|
@ -1435,13 +1441,16 @@ WalletService.prototype.getBalance = function(opts, cb, i) {
|
|||
|
||||
setTimeout(function() {
|
||||
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 (!_.isEqual(partialBalance, fullBalance)) {
|
||||
if (!skipped && !_.isEqual(partialBalance, fullBalance)) {
|
||||
log.info('Balance in active addresses differs from final balance');
|
||||
self._notify('BalanceUpdated', fullBalance, {
|
||||
isGlobal: true
|
||||
});
|
||||
} else if (skipped) {
|
||||
return;
|
||||
} else {
|
||||
// updates cache
|
||||
twoStepCache.lastEmpty = now;
|
||||
|
|
Loading…
Reference in New Issue