Limit all address query to MAX_TX_QUERY_LIMIT
- any address data API will now max out at 1000 (MAX_TX_QUERY_LIMIT) - For addrs with more than 1000 tx, use chained API query to get the complete data (like balance, txid, etc) - set parallel queue limit to 1: preserve consistency in API queries (and prevent incorrect data)
This commit is contained in:
parent
7f86e488e4
commit
1b6352573f
@ -220,9 +220,13 @@ AddressService.prototype.getAddressHistory = function(addresses, options, stream
|
||||
|
||||
if(results.items.length > MAX_TX_QUERY_LIMIT) { //remove items from array when overflown
|
||||
results.items.sort((a, b) => (b.__height || 0xffffffff) - (a.__height || 0xffffffff) || b.txid().localeCompare(a.txid()));
|
||||
let del_count = options.old_support ? results.items.length : results.items.length - MAX_TX_QUERY_LIMIT;
|
||||
let del_count = results.items.length - MAX_TX_QUERY_LIMIT;
|
||||
let start_index = options.old_support ? MAX_TX_QUERY_LIMIT : 0;
|
||||
results.items.splice(start_index, del_count);
|
||||
|
||||
if(!options.old_support)
|
||||
options.flag_stop = true; //limit has reached, stop quering db for more tx
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -315,6 +319,8 @@ AddressService.prototype.getAddressSummary = function(address, options, streamer
|
||||
streamer = () => null; //NULL fn
|
||||
}
|
||||
|
||||
var count = 0;
|
||||
|
||||
var result = {
|
||||
addrStr: address,
|
||||
balance: 0,
|
||||
@ -329,13 +335,20 @@ AddressService.prototype.getAddressSummary = function(address, options, streamer
|
||||
txApperances: 0,
|
||||
};
|
||||
|
||||
self.getAddressHistory(address, options, function(err, tx) {
|
||||
self._streamAddressSummary(address, options, function(err, tx) {
|
||||
|
||||
if(err)
|
||||
return log.error(err);
|
||||
|
||||
if(tx)
|
||||
if(tx) {
|
||||
count++;
|
||||
self._aggregateAddressSummaryResult(tx, address, result, options);
|
||||
}
|
||||
|
||||
if(count >= MAX_TX_QUERY_LIMIT) {//stop quering db when limit reached
|
||||
options.flag_stop = true;
|
||||
result.lastItem = tx.txid();
|
||||
}
|
||||
|
||||
streamer(null, tx);
|
||||
|
||||
@ -876,7 +889,7 @@ AddressService.prototype._streamAddressSummary = function(address, options, stre
|
||||
|
||||
self._transaction.getDetailedTransaction(id.txid, options, cb);
|
||||
|
||||
}, 4);
|
||||
}, 1);
|
||||
|
||||
//q.pause(); //pause and wait until queue is set (not needed)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user