From 3f511687d1ddbbcf8626a373dc8bc76cbdf2dd81 Mon Sep 17 00:00:00 2001 From: phiresky Date: Mon, 24 Jul 2023 14:02:15 +0000 Subject: [PATCH] minor fix --- crates/apub/src/activities/block/undo_block_user.rs | 2 +- crates/apub/src/fetcher/site_or_community_or_user.rs | 6 +++--- crates/apub/src/objects/instance.rs | 12 +----------- crates/db_schema/src/impls/activity.rs | 4 +++- crates/db_schema/src/schema.rs | 2 +- crates/db_schema/src/source/activity.rs | 2 +- crates/federate/src/util.rs | 6 +++--- crates/federate/src/worker.rs | 10 ++++------ .../up.sql | 6 +++--- 9 files changed, 20 insertions(+), 30 deletions(-) diff --git a/crates/apub/src/activities/block/undo_block_user.rs b/crates/apub/src/activities/block/undo_block_user.rs index 4ea67720e..50cb2d80d 100644 --- a/crates/apub/src/activities/block/undo_block_user.rs +++ b/crates/apub/src/activities/block/undo_block_user.rs @@ -8,7 +8,7 @@ use crate::{ }, activity_lists::AnnouncableActivities, insert_received_activity, - objects::{instance::remote_instance_inboxes, person::ApubPerson}, + objects::person::ApubPerson, protocol::activities::block::{block_user::BlockUser, undo_block_user::UndoBlockUser}, }; use activitypub_federation::{ diff --git a/crates/apub/src/fetcher/site_or_community_or_user.rs b/crates/apub/src/fetcher/site_or_community_or_user.rs index ed64306e3..2745ead57 100644 --- a/crates/apub/src/fetcher/site_or_community_or_user.rs +++ b/crates/apub/src/fetcher/site_or_community_or_user.rs @@ -42,8 +42,8 @@ impl Object for SiteOrCommunityOrUser { #[tracing::instrument(skip_all)] async fn read_from_id( - object_id: Url, - data: &Data, + _object_id: Url, + _data: &Data, ) -> Result, LemmyError> { unimplemented!(); } @@ -75,7 +75,7 @@ impl Object for SiteOrCommunityOrUser { } #[tracing::instrument(skip_all)] - async fn from_json(apub: Self::Kind, data: &Data) -> Result { + async fn from_json(_apub: Self::Kind, _data: &Data) -> Result { unimplemented!(); } } diff --git a/crates/apub/src/objects/instance.rs b/crates/apub/src/objects/instance.rs index 0a0793f5e..b171d5a3f 100644 --- a/crates/apub/src/objects/instance.rs +++ b/crates/apub/src/objects/instance.rs @@ -27,7 +27,7 @@ use lemmy_db_schema::{ site::{Site, SiteInsertForm}, }, traits::Crud, - utils::{naive_now, DbPool}, + utils::naive_now, }; use lemmy_utils::{ error::LemmyError, @@ -201,16 +201,6 @@ pub(in crate::objects) async fn fetch_instance_actor_for_object + C } } -pub(crate) async fn remote_instance_inboxes(pool: &mut DbPool<'_>) -> Result, LemmyError> { - Ok( - Site::read_remote_sites(pool) - .await? - .into_iter() - .map(|s| ApubSite::from(s).shared_inbox_or_inbox()) - .collect(), - ) -} - #[cfg(test)] pub(crate) mod tests { #![allow(clippy::unwrap_used)] diff --git a/crates/db_schema/src/impls/activity.rs b/crates/db_schema/src/impls/activity.rs index a7aab933f..576f85dc4 100644 --- a/crates/db_schema/src/impls/activity.rs +++ b/crates/db_schema/src/impls/activity.rs @@ -113,7 +113,9 @@ mod tests { ap_id: ap_id.clone(), data: data.clone(), sensitive, - actor_apub_id: Url::parse("http://example.com/u/exampleuser").unwrap(), + actor_apub_id: Url::parse("http://example.com/u/exampleuser") + .unwrap() + .into(), actor_type: ActorType::Person, send_targets: ActivitySendTargets::empty(), }; diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 46cfb66b9..2e1e6eed6 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -803,7 +803,7 @@ diesel::table! { published -> Timestamp, send_targets -> Jsonb, actor_type -> ActorTypeEnum, - actor_apub_id -> Text, + actor_apub_id -> Nullable, } } diff --git a/crates/db_schema/src/source/activity.rs b/crates/db_schema/src/source/activity.rs index 195d953cb..cef101ccc 100644 --- a/crates/db_schema/src/source/activity.rs +++ b/crates/db_schema/src/source/activity.rs @@ -74,7 +74,7 @@ pub struct SentActivity { pub published: chrono::NaiveDateTime, pub send_targets: ActivitySendTargets, pub actor_type: ActorType, - pub actor_apub_id: DbUrl, + pub actor_apub_id: Option, } #[derive(Insertable)] #[diesel(table_name = sent_activity)] diff --git a/crates/federate/src/util.rs b/crates/federate/src/util.rs index 0b007e70d..80de3a0d8 100644 --- a/crates/federate/src/util.rs +++ b/crates/federate/src/util.rs @@ -103,7 +103,7 @@ pub async fn get_actor_cached( Result::<_, anyhow::Error>::Ok(Arc::new(person)) }) .await - .map_err(|e| anyhow::anyhow!("err getting actor: {e}")) + .map_err(|e| anyhow::anyhow!("err getting actor: {e:?}")) } /// intern urls to reduce memory usage @@ -149,7 +149,7 @@ pub async fn get_activity_cached( Ok(Some(Arc::new((row, activity_actual)))) }) .await - .map_err(|e| anyhow::anyhow!("err getting activity: {e}")) + .map_err(|e| anyhow::anyhow!("err getting activity: {e:?}")) } /// return the most current activity id (with 1 second cache) @@ -170,7 +170,7 @@ pub async fn get_latest_activity_id(pool: &mut DbPool<'_>) -> Result anyhow::Result::<_, anyhow::Error>::Ok(latest_id as ActivityId) }) .await - .map_err(|e| anyhow::anyhow!("err getting id: {e}")) + .map_err(|e| anyhow::anyhow!("err getting id: {e:?}")) } /// how long to sleep based on how many retries have already happened diff --git a/crates/federate/src/worker.rs b/crates/federate/src/worker.rs index 34883c688..5c9910e14 100644 --- a/crates/federate/src/worker.rs +++ b/crates/federate/src/worker.rs @@ -93,12 +93,10 @@ pub async fn instance_worker( state.last_successful_id = id; continue; } - let actor = get_actor_cached( - &mut pool, - activity.actor_type, - activity.actor_apub_id.deref(), - ) - .await?; + let Some(actor_apub_id) = &activity.actor_apub_id else { + continue; // activity was inserted before persistent queue was activated + }; + let actor = get_actor_cached(&mut pool, activity.actor_type, actor_apub_id).await?; let inbox_urls = inbox_urls.into_iter().map(|e| (*e).clone()).collect(); let requests = prepare_raw(object, actor.as_ref(), inbox_urls, &data) diff --git a/migrations/2023-08-01-115243_persistent-activity-queue/up.sql b/migrations/2023-08-01-115243_persistent-activity-queue/up.sql index 54688d6f1..454cc4660 100644 --- a/migrations/2023-08-01-115243_persistent-activity-queue/up.sql +++ b/migrations/2023-08-01-115243_persistent-activity-queue/up.sql @@ -4,15 +4,15 @@ CREATE TYPE actor_type_enum AS enum( 'person' ); +-- actor_apub_id only null for old entries ALTER TABLE sent_activity ADD COLUMN send_targets jsonb NOT NULL DEFAULT '{"inboxes": [], "community_followers_of": [], "all_instances": false}', ADD COLUMN actor_type actor_type_enum NOT NULL DEFAULT 'person', - ADD COLUMN actor_apub_id text NOT NULL DEFAULT ''; + ADD COLUMN actor_apub_id text DEFAULT NULL; ALTER TABLE sent_activity ALTER COLUMN send_targets DROP DEFAULT, - ALTER COLUMN actor_type DROP DEFAULT, - ALTER COLUMN actor_apub_id DROP DEFAULT; + ALTER COLUMN actor_type DROP DEFAULT; CREATE TABLE federation_queue_state( domain text PRIMARY KEY,