Speed up mempool loop.

This commit is contained in:
softsimon 2020-06-09 02:32:24 +07:00
parent 0177224eba
commit ea708de9fb
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7

View File

@ -122,11 +122,15 @@ class Mempool {
}
}
// Replace mempool to clear deleted transactions
// Index object for faster search
const transactionsObject = {};
transactions.forEach((txId) => transactionsObject[txId] = true);
// Replace mempool to separate deleted transactions
const newMempool = {};
const deletedTransactions: TransactionExtended[] = [];
for (const tx in this.mempoolCache) {
if (transactions.indexOf(tx) > -1) {
if (transactionsObject[tx]) {
newMempool[tx] = this.mempoolCache[tx];
} else {
deletedTransactions.push(this.mempoolCache[tx]);