From b375b693beffe00516199e163445cc7bb3fbc61d Mon Sep 17 00:00:00 2001 From: dull b Date: Tue, 4 Jul 2023 03:25:02 +0000 Subject: [PATCH] Fix fetch_local_site_data --- crates/apub/src/activities/block/mod.rs | 5 +---- crates/apub/src/api/resolve_object.rs | 2 +- crates/apub/src/lib.rs | 13 ++++++------- crates/apub/src/objects/comment.rs | 2 +- crates/apub/src/objects/community.rs | 2 +- crates/apub/src/objects/instance.rs | 2 +- crates/apub/src/objects/person.rs | 2 +- crates/apub/src/objects/post.rs | 2 +- crates/apub/src/objects/private_message.rs | 2 +- crates/apub/src/protocol/objects/group.rs | 2 +- 10 files changed, 15 insertions(+), 19 deletions(-) diff --git a/crates/apub/src/activities/block/mod.rs b/crates/apub/src/activities/block/mod.rs index e7b603455..cf13a866b 100644 --- a/crates/apub/src/activities/block/mod.rs +++ b/crates/apub/src/activities/block/mod.rs @@ -118,10 +118,7 @@ impl SiteOrCommunity { } } -async fn generate_cc( - target: &SiteOrCommunity, - mut conn: impl DbConn, -) -> Result, LemmyError> { +async fn generate_cc(target: &SiteOrCommunity, conn: impl DbConn) -> Result, LemmyError> { Ok(match target { SiteOrCommunity::Site(_) => Site::read_remote_sites(conn) .await? diff --git a/crates/apub/src/api/resolve_object.rs b/crates/apub/src/api/resolve_object.rs index 0f982707c..784278339 100644 --- a/crates/apub/src/api/resolve_object.rs +++ b/crates/apub/src/api/resolve_object.rs @@ -33,7 +33,7 @@ pub async fn resolve_object( async fn convert_response( object: SearchableObjects, user_id: PersonId, - mut conn: impl DbConn, + conn: impl DbConn, ) -> Result, LemmyError> { use SearchableObjects::*; let removed_or_deleted; diff --git a/crates/apub/src/lib.rs b/crates/apub/src/lib.rs index 33eeb552e..0252e0aa0 100644 --- a/crates/apub/src/lib.rs +++ b/crates/apub/src/lib.rs @@ -9,7 +9,7 @@ use lemmy_db_schema::{ local_site::LocalSite, }, traits::Crud, - utils::{get_conn, DbConn, DbPool}, + utils::{get_conn, DbPool}, }; use lemmy_utils::{error::LemmyError, settings::structs::Settings}; use once_cell::sync::Lazy; @@ -38,8 +38,7 @@ pub struct VerifyUrlData(pub DbPool); #[async_trait] impl UrlVerifier for VerifyUrlData { async fn verify(&self, url: &Url) -> Result<(), &'static str> { - let mut conn = get_conn(&self.0).await.expect("get connection"); - let local_site_data = fetch_local_site_data(&mut *conn) + let local_site_data = fetch_local_site_data(&self.0) .await .expect("read local site data"); check_apub_id_valid(url, &local_site_data)?; @@ -99,12 +98,12 @@ pub(crate) struct LocalSiteData { } pub(crate) async fn fetch_local_site_data( - mut conn: impl DbConn, + pool: &DbPool, ) -> Result { // LocalSite may be missing - let local_site = LocalSite::read(&mut *conn).await.ok(); - let allowed_instances = Instance::allowlist(&mut *conn).await?; - let blocked_instances = Instance::blocklist(&mut *conn).await?; + let local_site = LocalSite::read(get_conn(pool).await?).await.ok(); + let allowed_instances = Instance::allowlist(get_conn(pool).await?).await?; + let blocked_instances = Instance::blocklist(get_conn(pool).await?).await?; Ok(LocalSiteData { local_site, diff --git a/crates/apub/src/objects/comment.rs b/crates/apub/src/objects/comment.rs index 2c00e6329..65354c345 100644 --- a/crates/apub/src/objects/comment.rs +++ b/crates/apub/src/objects/comment.rs @@ -132,7 +132,7 @@ impl Object for ApubComment { verify_domains_match(note.attributed_to.inner(), note.id.inner())?; verify_is_public(¬e.to, ¬e.cc)?; let community = note.community(context).await?; - let local_site_data = fetch_local_site_data(context.conn().await?).await?; + let local_site_data = fetch_local_site_data(context.pool()).await?; check_apub_id_valid_with_strictness( note.id.inner(), diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index 3f0fb31ff..408596814 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -188,7 +188,7 @@ impl ApubCommunity { ) -> Result, LemmyError> { let id = self.id; - let local_site_data = fetch_local_site_data(context.conn().await?).await?; + let local_site_data = fetch_local_site_data(context.pool()).await?; let follows = CommunityFollowerView::for_community(context.conn().await?, id).await?; let inboxes: Vec = follows .into_iter() diff --git a/crates/apub/src/objects/instance.rs b/crates/apub/src/objects/instance.rs index 8b395263f..d51a3ecef 100644 --- a/crates/apub/src/objects/instance.rs +++ b/crates/apub/src/objects/instance.rs @@ -113,7 +113,7 @@ impl Object for ApubSite { expected_domain: &Url, data: &Data, ) -> Result<(), LemmyError> { - let local_site_data = fetch_local_site_data(data.conn().await?).await?; + let local_site_data = fetch_local_site_data(data.pool()).await?; check_apub_id_valid_with_strictness(apub.id.inner(), true, &local_site_data, data.settings())?; verify_domains_match(expected_domain, apub.id.inner())?; diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index 0462020e3..78d9b9acb 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -118,7 +118,7 @@ impl Object for ApubPerson { expected_domain: &Url, context: &Data, ) -> Result<(), LemmyError> { - let local_site_data = fetch_local_site_data(context.conn().await?).await?; + let local_site_data = fetch_local_site_data(context.pool()).await?; let slur_regex = &local_site_opt_to_slur_regex(&local_site_data.local_site); check_slurs(&person.preferred_username, slur_regex)?; diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index e0e405902..87786a8de 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -143,7 +143,7 @@ impl Object for ApubPost { verify_is_remote_object(page.id.inner(), context.settings())?; }; - let local_site_data = fetch_local_site_data(context.conn().await?).await?; + let local_site_data = fetch_local_site_data(context.pool()).await?; let community = page.community(context).await?; check_apub_id_valid_with_strictness( diff --git a/crates/apub/src/objects/private_message.rs b/crates/apub/src/objects/private_message.rs index 083cf01eb..c10d7b8c5 100644 --- a/crates/apub/src/objects/private_message.rs +++ b/crates/apub/src/objects/private_message.rs @@ -102,7 +102,7 @@ impl Object for ApubPrivateMessage { verify_domains_match(note.id.inner(), expected_domain)?; verify_domains_match(note.attributed_to.inner(), note.id.inner())?; - let local_site_data = fetch_local_site_data(context.conn().await?).await?; + let local_site_data = fetch_local_site_data(context.pool()).await?; check_apub_id_valid_with_strictness( note.id.inner(), diff --git a/crates/apub/src/protocol/objects/group.rs b/crates/apub/src/protocol/objects/group.rs index b3bd5d08c..2b32915af 100644 --- a/crates/apub/src/protocol/objects/group.rs +++ b/crates/apub/src/protocol/objects/group.rs @@ -80,7 +80,7 @@ impl Group { expected_domain: &Url, context: &LemmyContext, ) -> Result<(), LemmyError> { - let local_site_data = fetch_local_site_data(context.conn().await?).await?; + let local_site_data = fetch_local_site_data(context.pool()).await?; check_apub_id_valid_with_strictness( self.id.inner(),