Skip to content

Commit

Permalink
fix(db): ledger updates sort order (#441)
Browse files Browse the repository at this point in the history
* Fix ledger updates sort order

* Allow more sort strings
  • Loading branch information
Alexandcoats authored Jul 15, 2022
1 parent bf36dc4 commit df0786d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions bin/inx-chronicle/src/api/stardust/history/extractors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ impl FromStr for Sort {

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"asc" => Ok(Self::Ascending),
"desc" => Ok(Self::Descending),
"asc" | "oldest" => Ok(Self::Ascending),
"desc" | "newest" => Ok(Self::Descending),
_ => Err(ParseError::BadSortDescriptor),
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/db/collections/ledger_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,20 @@ 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 });
}
}
}

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();

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit df0786d

Please sign in to comment.