From df0786da13bfaca016c6da741925c5fc33ff553b Mon Sep 17 00:00:00 2001 From: Alexandcoats Date: Fri, 15 Jul 2022 11:58:19 -0400 Subject: [PATCH] fix(db): ledger updates sort order (#441) * Fix ledger updates sort order * Allow more sort strings --- .../src/api/stardust/history/extractors.rs | 4 ++-- src/db/collections/ledger_update.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bin/inx-chronicle/src/api/stardust/history/extractors.rs b/bin/inx-chronicle/src/api/stardust/history/extractors.rs index 4af54ce79..e8abee761 100644 --- a/bin/inx-chronicle/src/api/stardust/history/extractors.rs +++ b/bin/inx-chronicle/src/api/stardust/history/extractors.rs @@ -29,8 +29,8 @@ impl FromStr for Sort { fn from_str(s: &str) -> Result { match s { - "asc" => Ok(Self::Ascending), - "desc" => Ok(Self::Descending), + "asc" | "oldest" => Ok(Self::Ascending), + "desc" | "newest" => Ok(Self::Descending), _ => Err(ParseError::BadSortDescriptor), } } diff --git a/src/db/collections/ledger_update.rs b/src/db/collections/ledger_update.rs index e34654ea4..1ecc4aadb 100644 --- a/src/db/collections/ledger_update.rs +++ b/src/db/collections/ledger_update.rs @@ -187,10 +187,10 @@ impl MongoDb { if let Some(output_id) = start_output_id { match order { SortOrder::Newest => { - filter.insert("output_id", doc! { "$lte": output_id }); + filter.insert("output_id", doc! { "$gte": output_id }); } SortOrder::Oldest => { - filter.insert("output_id", doc! { "$gte": output_id }); + filter.insert("output_id", doc! { "$lte": output_id }); } } } @@ -198,9 +198,9 @@ impl MongoDb { let options = FindOptions::builder() .limit(page_size as i64) .sort(if order.is_newest() { - inverse_ledger_index() - } else { ledger_index() + } else { + inverse_ledger_index() }) .build(); @@ -251,9 +251,9 @@ impl MongoDb { let options = FindOptions::builder() .limit(page_size as i64) .sort(if order.is_newest() { - inverse_ledger_index() - } else { ledger_index() + } else { + inverse_ledger_index() }) .build();