add lock
This commit is contained in:
parent
85156a8898
commit
3a75b38232
|
@ -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…
Reference in New Issue