]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/objects/community.rs
Cache & Optimize Woodpecker CI (#3450)
[lemmy.git] / crates / apub / src / objects / community.rs
index 672b25ebf9e7942ed25b7ef6e3a4c77b87545a7e..75eb941b1b3af0589cf29782277e4ef6e388c4c9 100644 (file)
@@ -14,7 +14,6 @@ use activitypub_federation::{
   traits::{Actor, Object},
 };
 use chrono::NaiveDateTime;
-use itertools::Itertools;
 use lemmy_api_common::{
   context::LemmyContext,
   utils::{generate_featured_url, generate_moderators_url, generate_outbox_url},
@@ -67,7 +66,7 @@ impl Object for ApubCommunity {
     context: &Data<Self::DataType>,
   ) -> Result<Option<Self>, LemmyError> {
     Ok(
-      Community::read_from_apub_id(context.pool(), &object_id.into())
+      Community::read_from_apub_id(&mut context.pool(), &object_id.into())
         .await?
         .map(Into::into),
     )
@@ -76,15 +75,15 @@ impl Object for ApubCommunity {
   #[tracing::instrument(skip_all)]
   async fn delete(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
     let form = CommunityUpdateForm::builder().deleted(Some(true)).build();
-    Community::update(context.pool(), self.id, &form).await?;
+    Community::update(&mut context.pool(), self.id, &form).await?;
     Ok(())
   }
 
   #[tracing::instrument(skip_all)]
   async fn into_json(self, data: &Data<Self::DataType>) -> Result<Group, LemmyError> {
     let community_id = self.id;
-    let langs = CommunityLanguage::read(data.pool(), community_id).await?;
-    let language = LanguageTag::new_multiple(langs, data.pool()).await?;
+    let langs = CommunityLanguage::read(&mut data.pool(), community_id).await?;
+    let language = LanguageTag::new_multiple(langs, &mut data.pool()).await?;
 
     let group = Group {
       kind: GroupType::Group,
@@ -131,10 +130,11 @@ impl Object for ApubCommunity {
     let instance_id = fetch_instance_actor_for_object(&group.id, context).await?;
 
     let form = Group::into_insert_form(group.clone(), instance_id);
-    let languages = LanguageTag::to_language_id_multiple(group.language, context.pool()).await?;
+    let languages =
+      LanguageTag::to_language_id_multiple(group.language, &mut context.pool()).await?;
 
-    let community = Community::create(context.pool(), &form).await?;
-    CommunityLanguage::update(context.pool(), languages, community.id).await?;
+    let community = Community::create(&mut context.pool(), &form).await?;
+    CommunityLanguage::update(&mut context.pool(), languages, community.id).await?;
 
     let community: ApubCommunity = community.into();
 
@@ -187,18 +187,12 @@ impl ApubCommunity {
   ) -> Result<Vec<Url>, LemmyError> {
     let id = self.id;
 
-    let local_site_data = local_site_data_cached(context.pool()).await?;
-    let follows = CommunityFollowerView::for_community(context.pool(), id).await?;
+    let local_site_data = local_site_data_cached(&mut context.pool()).await?;
+    let follows =
+      CommunityFollowerView::get_community_follower_inboxes(&mut context.pool(), id).await?;
     let inboxes: Vec<Url> = follows
       .into_iter()
-      .filter(|f| !f.follower.local)
-      .map(|f| {
-        f.follower
-          .shared_inbox_url
-          .unwrap_or(f.follower.inbox_url)
-          .into()
-      })
-      .unique()
+      .map(Into::into)
       .filter(|inbox: &Url| inbox.host_str() != Some(&context.settings().hostname))
       // Don't send to blocked instances
       .filter(|inbox| check_apub_id_valid(inbox, &local_site_data).is_ok())
@@ -210,6 +204,9 @@ impl ApubCommunity {
 
 #[cfg(test)]
 pub(crate) mod tests {
+  #![allow(clippy::unwrap_used)]
+  #![allow(clippy::indexing_slicing)]
+
   use super::*;
   use crate::{
     objects::{instance::tests::parse_lemmy_instance, tests::init_context},
@@ -247,9 +244,9 @@ pub(crate) mod tests {
     assert!(!community.local);
     assert_eq!(community.description.as_ref().unwrap().len(), 132);
 
-    Community::delete(context.pool(), community.id)
+    Community::delete(&mut context.pool(), community.id)
       .await
       .unwrap();
-    Site::delete(context.pool(), site.id).await.unwrap();
+    Site::delete(&mut context.pool(), site.id).await.unwrap();
   }
 }