fix: try fetching following/followers, dont fail

This commit is contained in:
əlemi 2024-04-30 16:47:34 +02:00
parent 938d219d7d
commit 6f033de946
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -88,22 +88,32 @@ impl Fetcher for Context {
// TODO try fetching these numbers from audience/generator fields to avoid making 2 more GETs // TODO try fetching these numbers from audience/generator fields to avoid making 2 more GETs
if let Some(followers_url) = &user_model.followers { if let Some(followers_url) = &user_model.followers {
let user_followers = Self::request( let req = Self::request(
Method::GET, followers_url, None, &format!("https://{}", self.domain()), &self.app().private_key, self.domain(), Method::GET, followers_url, None,
).await?.json::<serde_json::Value>().await?; &format!("https://{}", self.domain()), &self.app().private_key, self.domain(),
).await;
if let Ok(res) = req {
if let Ok(user_followers) = res.json::<serde_json::Value>().await {
if let Some(total) = user_followers.total_items() { if let Some(total) = user_followers.total_items() {
user_model.followers_count = total as i64; user_model.followers_count = total as i64;
} }
} }
}
}
if let Some(following_url) = &user_model.following { if let Some(following_url) = &user_model.following {
let user_following = Self::request( let req = Self::request(
Method::GET, following_url, None, &format!("https://{}", self.domain()), &self.app().private_key, self.domain(), Method::GET, following_url, None,
).await?.json::<serde_json::Value>().await?; &format!("https://{}", self.domain()), &self.app().private_key, self.domain(),
).await;
if let Ok(res) = req {
if let Ok(user_following) = res.json::<serde_json::Value>().await {
if let Some(total) = user_following.total_items() { if let Some(total) = user_following.total_items() {
user_model.following_count = total as i64; user_model.following_count = total as i64;
} }
} }
}
}
// TODO this may fail: while fetching, remote server may fetch our service actor. // TODO this may fail: while fetching, remote server may fetch our service actor.
// if it does so with http signature, we will fetch that actor in background // if it does so with http signature, we will fetch that actor in background