filter out users with an empty profile
This commit is contained in:
parent
862ccfa455
commit
f50141ef23
2 changed files with 33 additions and 7 deletions
36
src/main.rs
36
src/main.rs
|
@ -57,6 +57,15 @@ struct Db {
|
|||
}
|
||||
|
||||
impl UserData {
|
||||
fn is_empty(&self) -> bool {
|
||||
self.full_name.is_none()
|
||||
&& self.location.is_none()
|
||||
&& self.website.is_none()
|
||||
&& self.description.is_none()
|
||||
&& self.repos.is_empty()
|
||||
&& self.issues.is_empty()
|
||||
}
|
||||
|
||||
fn to_tokens(&self) -> Vec<String> {
|
||||
let mut text = String::new();
|
||||
let mut add = |s: &str| {
|
||||
|
@ -226,6 +235,14 @@ async fn scrape_users(forge: &Forgejo) -> anyhow::Result<Vec<forgejo_api::struct
|
|||
async fn get_users_data(forge: &Forgejo) -> anyhow::Result<HashMap<UserId, UserData>> {
|
||||
let mut data = HashMap::new();
|
||||
|
||||
let discard_empty = |o: Option<String>| {
|
||||
match o {
|
||||
None => None,
|
||||
Some(s) if s.is_empty() => None,
|
||||
Some(s) => Some(s),
|
||||
}
|
||||
};
|
||||
|
||||
eprintln!("Fetching users...");
|
||||
for user in scrape_users(&forge).await? {
|
||||
let Some(id) = user.id else {
|
||||
|
@ -248,10 +265,10 @@ async fn get_users_data(forge: &Forgejo) -> anyhow::Result<HashMap<UserId, UserD
|
|||
UserData {
|
||||
login,
|
||||
email,
|
||||
full_name: user.full_name,
|
||||
location: user.location,
|
||||
website: user.website,
|
||||
description: user.description,
|
||||
full_name: discard_empty(user.full_name),
|
||||
location: discard_empty(user.location),
|
||||
website: discard_empty(user.website),
|
||||
description: discard_empty(user.description),
|
||||
repos: Vec::new(),
|
||||
issues: Vec::new(),
|
||||
},
|
||||
|
@ -289,7 +306,7 @@ async fn get_users_data(forge: &Forgejo) -> anyhow::Result<HashMap<UserId, UserD
|
|||
RepoId(id),
|
||||
RepoData {
|
||||
name: repo_name,
|
||||
description: repo.description,
|
||||
description: discard_empty(repo.description),
|
||||
},
|
||||
));
|
||||
}
|
||||
|
@ -328,6 +345,12 @@ async fn get_users_data(forge: &Forgejo) -> anyhow::Result<HashMap<UserId, UserD
|
|||
));
|
||||
}
|
||||
|
||||
// discard users with an entirely empty profile: there is nothing useful we
|
||||
// can say about them
|
||||
let data = data
|
||||
.into_iter()
|
||||
.filter(|(_, user)| !user.is_empty())
|
||||
.collect();
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
|
@ -409,7 +432,8 @@ 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<_> = db.unclassified_users()
|
||||
let mut users: Vec<_> = db
|
||||
.unclassified_users()
|
||||
.into_iter()
|
||||
.map(|(id, u)| (id, u, *db.score.get(id).unwrap()))
|
||||
.collect();
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
{% macro compact(name, desc) %}
|
||||
{% if desc | length <= 150 %}
|
||||
{% if not desc %}
|
||||
{{ name }}
|
||||
{% elif desc | length <= 150 %}
|
||||
{{ name }} | {{ desc }}
|
||||
{% else %}
|
||||
<details>
|
||||
|
|
Loading…
Reference in a new issue