From 87eaa5ef67900a7d457560e7df821e95debd58ec Mon Sep 17 00:00:00 2001 From: Alexandcoats Date: Fri, 17 Mar 2023 14:14:07 -0400 Subject: [PATCH] fix(db): remove parents index and fix the query (#1195) * Remove parents index, use hint instead * Fix children query * Imports --- src/bin/inx-chronicle/migrations/migrate_1.rs | 1 + src/db/mongodb/collections/block.rs | 17 +++++------------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/bin/inx-chronicle/migrations/migrate_1.rs b/src/bin/inx-chronicle/migrations/migrate_1.rs index e3940fe0a..6119c5c67 100644 --- a/src/bin/inx-chronicle/migrations/migrate_1.rs +++ b/src/bin/inx-chronicle/migrations/migrate_1.rs @@ -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(()) } diff --git a/src/db/mongodb/collections/block.rs b/src/db/mongodb/collections/block.rs index 67a255ea3..3a67f7c10 100644 --- a/src/db/mongodb/collections/block.rs +++ b/src/db/mongodb/collections/block.rs @@ -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(()) } } @@ -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 } }, ],