Skip to content

Commit

Permalink
perf(db): wallet partial indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
nitsujlangston committed Nov 13, 2018
1 parent 4a465c2 commit 65e72d4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/bitcore-node/src/models/coin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ class Coin extends BaseModel<ICoin> {
}
);
this.collection.createIndex({ address: 1 }, { background: true });
this.collection.createIndex({ mintHeight: 1, chain: 1, network: 1 }, { background: true });
this.collection.createIndex({ chain: 1, network: 1, mintHeight: 1 }, { background: true });
this.collection.createIndex({ spentTxid: 1 }, { background: true, sparse: true });
this.collection.createIndex({ spentHeight: 1, chain: 1, network: 1 }, { background: true });
this.collection.createIndex({ wallets: 1, spentHeight: 1 }, { background: true, sparse: true });
this.collection.createIndex({ chain: 1, network: 1, spentHeight: 1 }, { background: true });
this.collection.createIndex({ wallets: 1, spentHeight: 1 }, { background: true, partialFilterExpression: { 'wallets.0': { $exists: true } } });
}

getBalance(params: { query: any }) {
Expand Down
4 changes: 2 additions & 2 deletions packages/bitcore-node/src/models/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export class Transaction extends BaseModel<ITransaction> {

onConnect() {
this.collection.createIndex({ txid: 1 }, { background: true });
this.collection.createIndex({ blockHeight: 1, chain: 1, network: 1 }, { background: true });
this.collection.createIndex({ chain: 1, network: 1, blockHeight: 1 }, { background: true });
this.collection.createIndex({ blockHash: 1 }, { background: true });
this.collection.createIndex({ blockTimeNormalized: 1, chain: 1, network: 1 }, { background: true });
this.collection.createIndex({ chain: 1, network: 1, blockTimeNormalized: 1 }, { background: true });
this.collection.createIndex({ wallets: 1, blockTimeNormalized: 1 }, { background: true, partialFilterExpression: { 'wallets.0': { $exists: true } } });
this.collection.createIndex({ wallets: 1, blockHeight: 1 }, { background: true, partialFilterExpression: { 'wallets.0': { $exists: true } } });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,13 @@ export class InternalStateProvider implements CSP.IChainStateService {
}

async getWalletBalance(params: CSP.GetWalletBalanceParams) {
let query = { wallets: params.wallet._id };
let query = { wallets: params.wallet._id, 'wallets.0': { $exists: true } };
return CoinModel.getBalance({ query });
}

async streamWalletUtxos(params: CSP.StreamWalletUtxosParams) {
const { wallet, limit, args = {}, stream } = params;
let query: any = { wallets: wallet._id };
let query: any = { wallets: wallet._id, 'wallets.0': { $exists: true } };
if (args.includeSpent !== 'true') {
query.spentHeight = { $lt: SpentHeightIndicators.pending };
}
Expand Down

0 comments on commit 65e72d4

Please sign in to comment.