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) {
var self = this;
self.storage.fetchAddresses(self.walletId, function(err, addresses) {
if (err) return cb(err);
self._getBalanceFromAddresses({
coin: opts.coin,
addresses: addresses
}, function(err, balance) {
// This lock is to prevent server starvation on big wallets
self._runLocked(cb, function(cb) {
self.storage.fetchAddresses(self.walletId, function(err, addresses) {
if (err) return cb(err);
self._getBalanceFromAddresses({
coin: opts.coin,
addresses: addresses
}, function(err, balance) {
if (err) return cb(err);
// Update cache
var withBalance = _.map(balance.byAddress, 'address')
self.storage.storeAddressesWithBalance(self.walletId, withBalance, function(err) {
if (err) {
log.warn('Could not update wallet cache', err);
}
return cb(null, balance);
// Update cache
var withBalance = _.map(balance.byAddress, 'address')
self.storage.storeAddressesWithBalance(self.walletId, withBalance, function(err) {
if (err) {
log.warn('Could not update wallet cache', err);
}
return cb(null, balance);
});
});
});
});

Loading…
Cancel
Save