From 8e3ee367f491cb5cd19802689f2127a0717afb8c Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 5 Nov 2020 16:37:55 +0100 Subject: [PATCH] Remove user_id column from actvity table --- lemmy_apub/src/activities/send/community.rs | 4 ---- lemmy_apub/src/activities/send/user.rs | 4 ---- lemmy_apub/src/activity_queue.rs | 2 +- lemmy_apub/src/inbox/community_inbox.rs | 10 +--------- lemmy_apub/src/inbox/shared_inbox.rs | 9 +-------- lemmy_apub/src/inbox/user_inbox.rs | 9 +-------- lemmy_apub/src/lib.rs | 6 +----- lemmy_db/src/activity.rs | 5 ----- lemmy_db/src/schema.rs | 2 -- 9 files changed, 5 insertions(+), 46 deletions(-) diff --git a/lemmy_apub/src/activities/send/community.rs b/lemmy_apub/src/activities/send/community.rs index 446ce6f34..ef990c24c 100644 --- a/lemmy_apub/src/activities/send/community.rs +++ b/lemmy_apub/src/activities/send/community.rs @@ -42,10 +42,6 @@ impl ActorType for Community { self.private_key.to_owned() } - fn user_id(&self) -> i32 { - self.creator_id - } - async fn send_follow( &self, _follow_actor_id: &Url, diff --git a/lemmy_apub/src/activities/send/user.rs b/lemmy_apub/src/activities/send/user.rs index c4d287a56..2759e8f98 100644 --- a/lemmy_apub/src/activities/send/user.rs +++ b/lemmy_apub/src/activities/send/user.rs @@ -32,10 +32,6 @@ impl ActorType for User_ { self.private_key.to_owned() } - fn user_id(&self) -> i32 { - self.id - } - /// As a given local user, send out a follow request to a remote community. async fn send_follow( &self, diff --git a/lemmy_apub/src/activity_queue.rs b/lemmy_apub/src/activity_queue.rs index c8c8af37e..ac96227dc 100644 --- a/lemmy_apub/src/activity_queue.rs +++ b/lemmy_apub/src/activity_queue.rs @@ -219,7 +219,7 @@ where // might send the same ap_id if insert_into_db { let id = activity.id().context(location_info!())?; - insert_activity(id, actor.user_id(), activity.clone(), true, pool).await?; + insert_activity(id, activity.clone(), true, pool).await?; } for i in inboxes { diff --git a/lemmy_apub/src/inbox/community_inbox.rs b/lemmy_apub/src/inbox/community_inbox.rs index ffc5f6d71..0e7ad3315 100644 --- a/lemmy_apub/src/inbox/community_inbox.rs +++ b/lemmy_apub/src/inbox/community_inbox.rs @@ -88,20 +88,12 @@ pub async fn community_inbox( let any_base = activity.clone().into_any_base()?; let kind = activity.kind().context(location_info!())?; - let user_id = user.id; let res = match kind { ValidTypes::Follow => handle_follow(any_base, user, community, &context).await, ValidTypes::Undo => handle_undo_follow(any_base, user, community, &context).await, }; - insert_activity( - &activity_id, - user_id, - activity.clone(), - false, - context.pool(), - ) - .await?; + insert_activity(&activity_id, activity.clone(), false, context.pool()).await?; res } diff --git a/lemmy_apub/src/inbox/shared_inbox.rs b/lemmy_apub/src/inbox/shared_inbox.rs index 4457a1a6d..3c7fa1bfb 100644 --- a/lemmy_apub/src/inbox/shared_inbox.rs +++ b/lemmy_apub/src/inbox/shared_inbox.rs @@ -125,14 +125,7 @@ pub async fn shared_inbox( ValidTypes::Undo => receive_undo(&context, any_base, actor_id, request_counter).await, }; - insert_activity( - &activity_id, - actor.user_id(), - activity.clone(), - false, - context.pool(), - ) - .await?; + insert_activity(&activity_id, activity.clone(), false, context.pool()).await?; res } diff --git a/lemmy_apub/src/inbox/user_inbox.rs b/lemmy_apub/src/inbox/user_inbox.rs index 653a447c5..35ff5c7ad 100644 --- a/lemmy_apub/src/inbox/user_inbox.rs +++ b/lemmy_apub/src/inbox/user_inbox.rs @@ -107,14 +107,7 @@ pub async fn user_inbox( } }; - insert_activity( - &activity_id, - actor.user_id(), - activity.clone(), - false, - context.pool(), - ) - .await?; + insert_activity(&activity_id, activity.clone(), false, context.pool()).await?; res } diff --git a/lemmy_apub/src/lib.rs b/lemmy_apub/src/lib.rs index 4449c94f4..b2d64d53a 100644 --- a/lemmy_apub/src/lib.rs +++ b/lemmy_apub/src/lib.rs @@ -169,9 +169,6 @@ pub trait ActorType { fn public_key(&self) -> Option; fn private_key(&self) -> Option; - /// numeric id in the database, used for insert_activity - fn user_id(&self) -> i32; - async fn send_follow( &self, follow_actor_id: &Url, @@ -256,7 +253,6 @@ pub trait ActorType { /// persistent. pub async fn insert_activity( ap_id: &Url, - user_id: i32, activity: T, local: bool, pool: &DbPool, @@ -266,7 +262,7 @@ where { let ap_id = ap_id.to_string(); blocking(pool, move |conn| { - Activity::insert(conn, ap_id, user_id, &activity, local) + Activity::insert(conn, ap_id, &activity, local) }) .await??; Ok(()) diff --git a/lemmy_db/src/activity.rs b/lemmy_db/src/activity.rs index 539820fc2..3c67070b0 100644 --- a/lemmy_db/src/activity.rs +++ b/lemmy_db/src/activity.rs @@ -13,7 +13,6 @@ use std::{ pub struct Activity { pub id: i32, pub ap_id: String, - pub user_id: i32, pub data: Value, pub local: bool, pub published: chrono::NaiveDateTime, @@ -24,7 +23,6 @@ pub struct Activity { #[table_name = "activity"] pub struct ActivityForm { pub ap_id: String, - pub user_id: i32, pub data: Value, pub local: bool, pub updated: Option, @@ -59,18 +57,15 @@ impl Activity { pub fn insert( conn: &PgConnection, ap_id: String, - user_id: i32, data: &T, local: bool, ) -> Result where T: Serialize + Debug, { - debug!("inserting activity for user {}: ", user_id); debug!("{}", serde_json::to_string_pretty(&data)?); let activity_form = ActivityForm { ap_id, - user_id, data: serde_json::to_value(&data)?, local, updated: None, diff --git a/lemmy_db/src/schema.rs b/lemmy_db/src/schema.rs index c755009b1..b01236050 100644 --- a/lemmy_db/src/schema.rs +++ b/lemmy_db/src/schema.rs @@ -2,7 +2,6 @@ table! { activity (id) { id -> Int4, ap_id -> Text, - user_id -> Int4, data -> Jsonb, local -> Bool, published -> Timestamp, @@ -481,7 +480,6 @@ table! { } } -joinable!(activity -> user_ (user_id)); joinable!(comment -> post (post_id)); joinable!(comment -> user_ (creator_id)); joinable!(comment_like -> comment (comment_id));