Skip to content

Commit 0385138

Browse files
Merge branch 'indexImprovements' into v8.0.0
2 parents e9f816d + 6765f1d commit 0385138

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ class Coin extends BaseModel<ICoin> {
6464
}
6565
);
6666
this.collection.createIndex({ address: 1 }, { background: true });
67-
this.collection.createIndex({ mintHeight: 1, chain: 1, network: 1 }, { background: true });
67+
this.collection.createIndex({ chain: 1, network: 1, mintHeight: 1 }, { background: true });
6868
this.collection.createIndex({ spentTxid: 1 }, { background: true, sparse: true });
69-
this.collection.createIndex({ spentHeight: 1, chain: 1, network: 1 }, { background: true });
70-
this.collection.createIndex({ wallets: 1, spentHeight: 1 }, { background: true, sparse: true });
69+
this.collection.createIndex({ chain: 1, network: 1, spentHeight: 1 }, { background: true });
70+
this.collection.createIndex({ wallets: 1, spentHeight: 1, value: 1 }, { background: true, partialFilterExpression: { 'wallets.0': { $exists: true } } });
7171
}
7272

7373
getBalance(params: { query: any }) {
@@ -76,6 +76,7 @@ class Coin extends BaseModel<ICoin> {
7676
return this.collection
7777
.aggregate<{ balance: number }>([
7878
{ $match: query },
79+
{ $project: { value: 1, _id: 0 }},
7980
{
8081
$group: {
8182
_id: null,

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)