From f57f30441909af8545faa250382d92f04dd2a556 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 21 Nov 2024 12:22:14 +0100 Subject: [PATCH] feat: also fetch statuses count when updating users also use new Node::resolve() rather than making manual requests --- upub/core/src/traits/fetch.rs | 36 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/upub/core/src/traits/fetch.rs b/upub/core/src/traits/fetch.rs index 1aca561..026b431 100644 --- a/upub/core/src/traits/fetch.rs +++ b/upub/core/src/traits/fetch.rs @@ -297,30 +297,26 @@ impl Fetcher for crate::Context { 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 - if let Ok(followers_url) = document.followers().id() { - let req = Self::request( - Method::GET, &followers_url, None, - self.base(), self.pkey(), self.domain(), - ).await; - if let Ok(res) = req { - if let Ok(user_followers) = res.json::().await { - if let Ok(total) = user_followers.total_items() { - document = document.set_followers_count(Some(total)); - } + if document.followers_count().is_err() { + if let Ok(followers) = document.followers().resolve(self).await { + if let Ok(total) = followers.total_items() { + document = document.set_followers_count(Some(total)); } } } - if let Ok(following_url) = document.following().id() { - let req = Self::request( - Method::GET, &following_url, None, - self.base(), self.pkey(), self.domain(), - ).await; - if let Ok(res) = req { - if let Ok(user_following) = res.json::().await { - if let Ok(total) = user_following.total_items() { - document = document.set_following_count(Some(total)); - } + if document.following_count().is_err() { + if let Ok(following) = document.following().resolve(self).await { + if let Ok(total) = 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)); } } }