From 937b7a3ed21ad07481f26fefefbdbaae090fca09 Mon Sep 17 00:00:00 2001 From: cofob Date: Tue, 14 May 2024 23:16:28 +0400 Subject: [PATCH] Sort by ms --- src/crawler.rs | 8 ++++---- src/routes/redirect.rs | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/crawler.rs b/src/crawler.rs index 4021570..2ee8d6c 100644 --- a/src/crawler.rs +++ b/src/crawler.rs @@ -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, } } } diff --git a/src/routes/redirect.rs b/src/routes/redirect.rs index 8954640..e2bfee2 100644 --- a/src/routes/redirect.rs +++ b/src/routes/redirect.rs @@ -52,7 +52,8 @@ mod filters { pub fn sort_list(l: &[CrawledInstance]) -> ::askama::Result> { 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) } }