Browse Source

add lock

feat/2-step-opt
Matias Alejo Garcia 7 years ago
parent
commit
3a75b38232
No known key found for this signature in database GPG Key ID: 2470DB551277AB3
  1. 29
      lib/server.js

29
lib/server.js

@ -1277,21 +1277,24 @@ WalletService.prototype._getBalanceFromAddresses = function(opts, cb) {
WalletService.prototype._getBalanceOneStep = function(opts, cb) { WalletService.prototype._getBalanceOneStep = function(opts, cb) {
var self = this; var self = this;
self.storage.fetchAddresses(self.walletId, function(err, addresses) { // This lock is to prevent server starvation on big wallets
if (err) return cb(err); self._runLocked(cb, function(cb) {
self._getBalanceFromAddresses({ self.storage.fetchAddresses(self.walletId, function(err, addresses) {
coin: opts.coin,
addresses: addresses
}, function(err, balance) {
if (err) return cb(err); if (err) return cb(err);
self._getBalanceFromAddresses({
coin: opts.coin,
addresses: addresses
}, function(err, balance) {
if (err) return cb(err);
// Update cache // Update cache
var withBalance = _.map(balance.byAddress, 'address') var withBalance = _.map(balance.byAddress, 'address')
self.storage.storeAddressesWithBalance(self.walletId, withBalance, function(err) { self.storage.storeAddressesWithBalance(self.walletId, withBalance, function(err) {
if (err) { if (err) {
log.warn('Could not update wallet cache', err); log.warn('Could not update wallet cache', err);
} }
return cb(null, balance); return cb(null, balance);
});
}); });
}); });
}); });

Loading…
Cancel
Save