when selecting random users, still sort the selected users on screen

This commit is contained in:
Armaël Guéneau 2024-11-27 19:36:47 +01:00
parent f50141ef23
commit 6442dfe07b

View file

@ -443,7 +443,8 @@ async fn index(data: web::Data<AppState>, q: web::Query<SortSetting>) -> impl Re
users.shuffle(&mut rng); users.shuffle(&mut rng);
eprintln!("sorting..."); 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 // sort "legit first": by increasing score
Some("legit") => users.sort_by_key(|(_, _, score)| (score * 1000.) as u64), Some("legit") => users.sort_by_key(|(_, _, score)| (score * 1000.) as u64),
// keep the random order // keep the random order
@ -452,6 +453,10 @@ async fn index(data: web::Data<AppState>, q: web::Query<SortSetting>) -> impl Re
_ => users.sort_by_key(|(_, _, score)| 1000 - (score * 1000.) as u64), _ => users.sort_by_key(|(_, _, score)| 1000 - (score * 1000.) as u64),
}; };
users.truncate(50); 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 users_count = db.users.len();
let classified_count = db.is_spam.len(); let classified_count = db.is_spam.len();