Skip to content

Commit 65e72d4

Browse files
perf(db): wallet partial indexes
1 parent 4a465c2 commit 65e72d4

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ class Coin extends BaseModel<ICoin> {
6363
}
6464
);
6565
this.collection.createIndex({ address: 1 }, { background: true });
66-
this.collection.createIndex({ mintHeight: 1, chain: 1, network: 1 }, { background: true });
66+
this.collection.createIndex({ chain: 1, network: 1, mintHeight: 1 }, { background: true });
6767
this.collection.createIndex({ spentTxid: 1 }, { background: true, sparse: true });
68-
this.collection.createIndex({ spentHeight: 1, chain: 1, network: 1 }, { background: true });
69-
this.collection.createIndex({ wallets: 1, spentHeight: 1 }, { background: true, sparse: true });
68+
this.collection.createIndex({ chain: 1, network: 1, spentHeight: 1 }, { background: true });
69+
this.collection.createIndex({ wallets: 1, spentHeight: 1 }, { background: true, partialFilterExpression: { 'wallets.0': { $exists: true } } });
7070
}
7171

7272
getBalance(params: { query: any }) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ export class Transaction extends BaseModel<ITransaction> {
4040

4141
onConnect() {
4242
this.collection.createIndex({ txid: 1 }, { background: true });
43-
this.collection.createIndex({ blockHeight: 1, chain: 1, network: 1 }, { background: true });
43+
this.collection.createIndex({ chain: 1, network: 1, blockHeight: 1 }, { background: true });
4444
this.collection.createIndex({ blockHash: 1 }, { background: true });
45-
this.collection.createIndex({ blockTimeNormalized: 1, chain: 1, network: 1 }, { background: true });
45+
this.collection.createIndex({ chain: 1, network: 1, blockTimeNormalized: 1 }, { background: true });
4646
this.collection.createIndex({ wallets: 1, blockTimeNormalized: 1 }, { background: true, partialFilterExpression: { 'wallets.0': { $exists: true } } });
4747
this.collection.createIndex({ wallets: 1, blockHeight: 1 }, { background: true, partialFilterExpression: { 'wallets.0': { $exists: true } } });
4848
}

packages/bitcore-node/src/providers/chain-state/internal/internal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,13 @@ export class InternalStateProvider implements CSP.IChainStateService {
324324
}
325325

326326
async getWalletBalance(params: CSP.GetWalletBalanceParams) {
327-
let query = { wallets: params.wallet._id };
327+
let query = { wallets: params.wallet._id, 'wallets.0': { $exists: true } };
328328
return CoinModel.getBalance({ query });
329329
}
330330

331331
async streamWalletUtxos(params: CSP.StreamWalletUtxosParams) {
332332
const { wallet, limit, args = {}, stream } = params;
333-
let query: any = { wallets: wallet._id };
333+
let query: any = { wallets: wallet._id, 'wallets.0': { $exists: true } };
334334
if (args.includeSpent !== 'true') {
335335
query.spentHeight = { $lt: SpentHeightIndicators.pending };
336336
}

0 commit comments

Comments
 (0)