Skip to content

Commit

Permalink
fix(db): remove parents index and fix the query (#1195)
Browse files Browse the repository at this point in the history
* Remove parents index, use hint instead

* Fix children query

* Imports
  • Loading branch information
Alexandcoats authored Mar 17, 2023
1 parent 53de770 commit 87eaa5e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/bin/inx-chronicle/migrations/migrate_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl Migration for Migrate {
collection
.drop_index("output_immutable_alias_address_unlock_index", None)
.await?;
collection.drop_index("block_parents_index", None).await?;

Ok(())
}
Expand Down
17 changes: 5 additions & 12 deletions src/db/mongodb/collections/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,6 @@ impl MongoDbCollection for BlockCollection {
)
.await?;

self.create_index(
IndexModel::builder()
.keys(doc! { "block.parents": 1 })
.options(IndexOptions::builder().name("block_parents_index".to_string()).build())
.build(),
None,
)
.await?;

Ok(())
}
}
Expand Down Expand Up @@ -215,12 +206,14 @@ impl BlockCollection {
.aggregate(
[
doc! { "$match": {
"metadata.referenced_by_milestone_index": { "$gte": block_referenced_index },
"metadata.referenced_by_milestone_index": { "$lte": max_referenced_index },
"metadata.referenced_by_milestone_index": {
"$gte": block_referenced_index,
"$lte": max_referenced_index
},
"block.parents": block_id,
} },
doc! { "$skip": (page_size * page) as i64 },
doc! { "$sort": {"metadata.referenced_by_milestone_index": -1} },
doc! { "$skip": (page_size * page) as i64 },
doc! { "$limit": page_size as i64 },
doc! { "$project": { "_id": 1 } },
],
Expand Down

0 comments on commit 87eaa5e

Please sign in to comment.