feat: also fetch statuses count when updating users

also use new Node::resolve() rather than making manual requests
This commit is contained in:
əlemi 2024-11-21 12:22:14 +01:00
parent d7d450e942
commit f57f304419
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -297,30 +297,26 @@ impl Fetcher for crate::Context {
let _domain = self.fetch_domain(&crate::Context::server(&id), tx).await?; let _domain = self.fetch_domain(&crate::Context::server(&id), tx).await?;
// TODO try fetching these numbers from audience/generator fields to avoid making 2 more GETs every time // TODO try fetching these numbers from audience/generator fields to avoid making 2 more GETs every time
if let Ok(followers_url) = document.followers().id() { if document.followers_count().is_err() {
let req = Self::request( if let Ok(followers) = document.followers().resolve(self).await {
Method::GET, &followers_url, None, if let Ok(total) = followers.total_items() {
self.base(), self.pkey(), self.domain(), document = document.set_followers_count(Some(total));
).await;
if let Ok(res) = req {
if let Ok(user_followers) = res.json::<serde_json::Value>().await {
if let Ok(total) = user_followers.total_items() {
document = document.set_followers_count(Some(total));
}
} }
} }
} }
if let Ok(following_url) = document.following().id() { if document.following_count().is_err() {
let req = Self::request( if let Ok(following) = document.following().resolve(self).await {
Method::GET, &following_url, None, if let Ok(total) = following.total_items() {
self.base(), self.pkey(), self.domain(), document = document.set_following_count(Some(total));
).await; }
if let Ok(res) = req { }
if let Ok(user_following) = res.json::<serde_json::Value>().await { }
if let Ok(total) = user_following.total_items() {
document = document.set_following_count(Some(total)); if document.statuses_count().is_err() {
} if let Ok(outbox) = document.outbox().resolve(self).await {
if let Ok(total) = outbox.total_items() {
document = document.set_statuses_count(Some(total));
} }
} }
} }