From 972ef977218156a66dfbcd856c950d987496acfc Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 8 Jun 2024 05:45:41 +0200 Subject: [PATCH] fix: addressing of local objects --- upub/core/src/context.rs | 31 ------------------------------- upub/core/src/traits/address.rs | 10 ++++------ 2 files changed, 4 insertions(+), 37 deletions(-) diff --git a/upub/core/src/context.rs b/upub/core/src/context.rs index 1e25b400..bf15d819 100644 --- a/upub/core/src/context.rs +++ b/upub/core/src/context.rs @@ -140,37 +140,6 @@ impl Context { id.starts_with(self.base()) } - pub async fn is_local_internal_object(&self, internal: i64) -> Result { - model::object::Entity::find() - .filter(model::object::Column::Internal.eq(internal)) - .select_only() - .select_column(model::object::Column::Internal) - .into_tuple::() - .any(self.db()) - .await - } - - pub async fn is_local_internal_activity(&self, internal: i64) -> Result { - model::activity::Entity::find() - .filter(model::activity::Column::Internal.eq(internal)) - .select_only() - .select_column(model::activity::Column::Internal) - .into_tuple::() - .any(self.db()) - .await - } - - #[allow(unused)] - pub async fn is_local_internal_actor(&self, internal: i64) -> Result { - model::actor::Entity::find() - .filter(model::actor::Column::Internal.eq(internal)) - .select_only() - .select_column(model::actor::Column::Internal) - .into_tuple::() - .any(self.db()) - .await - } - pub async fn find_internal(&self, id: &str) -> Result, DbErr> { if let Some(internal) = model::object::Entity::ap_to_internal(id, self.db()).await? { return Ok(Some(Internal::Object(internal))); diff --git a/upub/core/src/traits/address.rs b/upub/core/src/traits/address.rs index 2729cd3c..4ffdab30 100644 --- a/upub/core/src/traits/address.rs +++ b/upub/core/src/traits/address.rs @@ -56,25 +56,23 @@ impl Addresser for crate::Context { async fn address_object(&self, object: &crate::model::object::Model, tx: &impl ConnectionTrait) -> Result<(), DbErr> { let to = expand_addressing(object.addressed(), tx).await?; - address_to(self, to, None, Some(object.internal), tx).await + address_to(self, to, None, Some(object.internal), self.is_local(&object.id), tx).await } async fn address_activity(&self, activity: &crate::model::activity::Model, tx: &impl ConnectionTrait) -> Result<(), DbErr> { let to = expand_addressing(activity.mentioning(), tx).await?; - address_to(self, to, Some(activity.internal), None, tx).await + address_to(self, to, Some(activity.internal), None, self.is_local(&activity.id), tx).await } } -async fn address_to(ctx: &crate::Context, to: Vec, aid: Option, oid: Option, tx: &impl ConnectionTrait) -> Result<(), DbErr> { +async fn address_to(ctx: &crate::Context, to: Vec, aid: Option, oid: Option, local: bool, tx: &impl ConnectionTrait) -> Result<(), DbErr> { // TODO address_to became kind of expensive, with these two selects right away and then another // select for each target we're addressing to... can this be improved?? - let local_activity = if let Some(x) = aid { ctx.is_local_internal_activity(x).await.unwrap_or(false) } else { false }; - let local_object = if let Some(x) = oid { ctx.is_local_internal_object(x).await.unwrap_or(false) } else { false }; let mut addressing = Vec::new(); for target in to.into_iter() .filter(|to| !to.is_empty()) .filter(|to| !to.ends_with("/followers")) - .filter(|to| local_activity || local_object || to.as_str() == apb::target::PUBLIC || ctx.is_local(to)) + .filter(|to| local || to.as_str() == apb::target::PUBLIC || ctx.is_local(to)) { let (server, actor) = if target == apb::target::PUBLIC { (None, None) } else { match (