Skip to content

Commit c4e66da

Browse files
loop and use projection
1 parent a823dd6 commit c4e66da

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

packages/bitcore-node/src/models/transaction.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -400,21 +400,21 @@ export class Transaction extends BaseModel<ITransaction> {
400400
if (!initialSyncComplete || !spendOps.length) {
401401
return;
402402
}
403-
const spentCoinsQuery = {
404-
chain, network, spentHeight: SpentHeightIndicators.pending, $or: spendOps.map(spendOp => {
405-
return {
406-
mintTxid: spendOp.updateOne.filter.mintTxid,
407-
mintIndex: spendOp.updateOne.filter.mintIndex,
408-
spentTxid: { $ne: spendOp.updateOne.update.$set.spentTxid }
409-
}
410-
})
411-
};
412-
const spendingCoins = await CoinModel.collection.find(spentCoinsQuery).toArray();
413-
if (spendingCoins.length) {
414-
let prunedTxs = {};
415-
for (const coin of spendingCoins) {
403+
let prunedTxs = {};
404+
for (const spendOp of spendOps) {
405+
let coin = await CoinModel.collection.findOne({
406+
chain,
407+
network,
408+
spentHeight: SpentHeightIndicators.pending,
409+
mintTxid: spendOp.updateOne.filter.mintTxid,
410+
mintIndex: spendOp.updateOne.filter.mintIndex,
411+
spentTxid: { $ne: spendOp.updateOne.update.$set.spentTxid }
412+
}, { projection: { spentTxid: 1 }});
413+
if (coin) {
416414
prunedTxs[coin.spentTxid] = true;
417415
}
416+
}
417+
if (Object.keys(prunedTxs).length) {
418418
prunedTxs = Object.keys(prunedTxs);
419419
await Promise.all([
420420
this.collection.update({ txid: { $in: prunedTxs } }, { $set: { blockHeight: SpentHeightIndicators.conflicting } }, { w: 0, j: false, multi: true }),

0 commit comments

Comments
 (0)