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