Skip to content

Commit

Permalink
Sort by ms
Browse files Browse the repository at this point in the history
  • Loading branch information
cofob committed May 14, 2024
1 parent c02cec0 commit 937b7a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/crawler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ pub enum CrawledInstanceStatus {

impl CrawledInstanceStatus {
/// Used for sorting values in index.html template.
pub fn as_u8(&self) -> u8 {
pub fn as_u8(&self) -> isize {
match self {
Self::Ok(_) => 3,
Self::TimedOut => 2,
Self::Unknown => 1,
Self::Ok(d) => isize::MAX - d.as_millis() as isize,
Self::TimedOut => -2,
Self::Unknown => -3,
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/routes/redirect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ mod filters {

pub fn sort_list(l: &[CrawledInstance]) -> ::askama::Result<Vec<CrawledInstance>> {
let mut new = l.to_owned();
new.sort_by(|a, b| b.status.as_u8().cmp(&a.status.as_u8()));
new.sort_by_key(|i| i.status.as_u8());
new.reverse();
Ok(new)
}
}
Expand Down

0 comments on commit 937b7a3

Please sign in to comment.