minor cleanup

This commit is contained in:
Armaël Guéneau 2024-11-23 13:28:43 +01:00
parent e6c6877940
commit 797de9b825
2 changed files with 8 additions and 8 deletions

View file

@ -150,6 +150,13 @@ impl Db {
serde_json::to_writer(BufWriter::new(file), &dat)?;
Ok(())
}
fn unclassified_users<'a>(&'a self) -> Vec<(&'a UserId, &'a UserData)> {
self.users
.iter()
.filter(|(user_id, _)| !self.is_spam.contains_key(&user_id))
.collect()
}
}
async fn scrape_repos(forge: &Forgejo) -> anyhow::Result<Vec<forgejo_api::structs::Repository>> {
@ -352,13 +359,6 @@ async fn load_db() -> anyhow::Result<(Db, Classifier)> {
Ok((db, classifier))
}
fn unclassified_users<'a>(db: &'a Db) -> Vec<(&'a UserId, &'a UserData)> {
db.users
.iter()
.filter(|(user_id, _)| !db.is_spam.contains_key(&user_id))
.collect()
}
fn set_spam(db: &mut Db, classifier: &mut Classifier, ids: &[(UserId, bool)]) {
eprintln!("updating classifier");
@ -409,7 +409,7 @@ async fn index(data: web::Data<AppState>, q: web::Query<SortSetting>) -> impl Re
let db = &data.db.lock().unwrap();
eprintln!("scoring users...");
let mut users: Vec<_> = unclassified_users(db)
let mut users: Vec<_> = db.unclassified_users()
.into_iter()
.map(|(id, u)| (id, u, *db.score.get(id).unwrap()))
.collect();

View file