From 6442dfe07ba28e75154f35c73dd41228683a0184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arma=C3=ABl=20Gu=C3=A9neau?= Date: Wed, 27 Nov 2024 19:36:47 +0100 Subject: [PATCH] when selecting random users, still sort the selected users on screen --- src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 76c7a5b..69c05c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -443,7 +443,8 @@ async fn index(data: web::Data, q: web::Query) -> impl Re users.shuffle(&mut rng); eprintln!("sorting..."); - match q.sort.as_ref().map(|s| s.as_str()) { + let sorting_req = q.sort.as_ref().map(|s| s.as_str()); + match &sorting_req { // sort "legit first": by increasing score Some("legit") => users.sort_by_key(|(_, _, score)| (score * 1000.) as u64), // keep the random order @@ -452,6 +453,10 @@ async fn index(data: web::Data, q: web::Query) -> impl Re _ => users.sort_by_key(|(_, _, score)| 1000 - (score * 1000.) as u64), }; users.truncate(50); + // sort the remaining batch if it is random: the result is easier to read + if let Some("random") = &sorting_req { + users.sort_by_key(|(_, _, score)| 1000 - (score * 1000.) as u64) + } let users_count = db.users.len(); let classified_count = db.is_spam.len();