From 16b235cd7b620c50c6866eb256806ccfcb0029fd Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 27 May 2024 20:29:26 -0700 Subject: [PATCH 01/21] Update like.rs --- crates/api/src/comment/like.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/api/src/comment/like.rs b/crates/api/src/comment/like.rs index d0aa4a6c2..aa76b91e6 100644 --- a/crates/api/src/comment/like.rs +++ b/crates/api/src/comment/like.rs @@ -59,7 +59,6 @@ pub async fn like_comment( let like_form = CommentLikeForm { comment_id: data.comment_id, - post_id: orig_comment.post.id, person_id: local_user_view.person.id, score: data.score, }; From db5082ae5ad5f2f55eae9239953fb076ac448275 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 27 May 2024 20:45:15 -0700 Subject: [PATCH 02/21] Update utils.rs --- crates/api_common/src/utils.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index bad3b8180..995d9dbbd 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -165,7 +165,6 @@ pub async fn update_read_comments( person_id, post_id, read_comments, - ..PersonPostAggregatesForm::default() }; PersonPostAggregates::upsert(pool, &person_post_agg_form) From 364e2169df382a2823f182737587811a7216c037 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 27 May 2024 20:46:46 -0700 Subject: [PATCH 03/21] Update create.rs --- crates/api_crud/src/comment/create.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/api_crud/src/comment/create.rs b/crates/api_crud/src/comment/create.rs index 2efd46964..48d3787c7 100644 --- a/crates/api_crud/src/comment/create.rs +++ b/crates/api_crud/src/comment/create.rs @@ -160,7 +160,6 @@ pub async fn create_comment( // You like your own comment by default let like_form = CommentLikeForm { comment_id: inserted_comment.id, - post_id: post.id, person_id: local_user_view.person.id, score: 1, }; From e30af55524bd19fdfae54e9e20a385fc67bb3ec3 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 27 May 2024 20:47:39 -0700 Subject: [PATCH 04/21] Update comment.rs --- crates/apub/src/activities/create_or_update/comment.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/apub/src/activities/create_or_update/comment.rs b/crates/apub/src/activities/create_or_update/comment.rs index 2406d2eb3..e068b5621 100644 --- a/crates/apub/src/activities/create_or_update/comment.rs +++ b/crates/apub/src/activities/create_or_update/comment.rs @@ -160,7 +160,6 @@ impl ActivityHandler for CreateOrUpdateNote { // author likes their own comment by default let like_form = CommentLikeForm { comment_id: comment.id, - post_id: comment.post_id, person_id: comment.creator_id, score: 1, }; From f6f4df95d7b4f24042e43a0626119bd100f0b278 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 27 May 2024 20:48:21 -0700 Subject: [PATCH 05/21] Update mod.rs --- crates/apub/src/activities/voting/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/apub/src/activities/voting/mod.rs b/crates/apub/src/activities/voting/mod.rs index 3e59cb7d0..7c39b2246 100644 --- a/crates/apub/src/activities/voting/mod.rs +++ b/crates/apub/src/activities/voting/mod.rs @@ -62,7 +62,6 @@ async fn vote_comment( let comment_id = comment.id; let like_form = CommentLikeForm { comment_id, - post_id: comment.post_id, person_id: actor.id, score: vote_type.into(), }; From 67798bdf052925589aef98baa842d59a36d9b022 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 27 May 2024 20:49:12 -0700 Subject: [PATCH 06/21] Update comment_aggregates.rs --- crates/db_schema/src/aggregates/comment_aggregates.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/db_schema/src/aggregates/comment_aggregates.rs b/crates/db_schema/src/aggregates/comment_aggregates.rs index 915d17b1d..1baa48881 100644 --- a/crates/db_schema/src/aggregates/comment_aggregates.rs +++ b/crates/db_schema/src/aggregates/comment_aggregates.rs @@ -118,7 +118,6 @@ mod tests { let comment_like = CommentLikeForm { comment_id: inserted_comment.id, - post_id: inserted_post.id, person_id: inserted_person.id, score: 1, }; @@ -137,7 +136,6 @@ mod tests { // Add a post dislike from the other person let comment_dislike = CommentLikeForm { comment_id: inserted_comment.id, - post_id: inserted_post.id, person_id: another_inserted_person.id, score: -1, }; From 9d2616ba8673ed35dbe7687c4b58aadcd20b2ad8 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 27 May 2024 20:49:51 -0700 Subject: [PATCH 07/21] Update person_aggregates.rs --- crates/db_schema/src/aggregates/person_aggregates.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/db_schema/src/aggregates/person_aggregates.rs b/crates/db_schema/src/aggregates/person_aggregates.rs index 03295173f..8315b5afc 100644 --- a/crates/db_schema/src/aggregates/person_aggregates.rs +++ b/crates/db_schema/src/aggregates/person_aggregates.rs @@ -101,7 +101,6 @@ mod tests { let mut comment_like = CommentLikeForm { comment_id: inserted_comment.id, person_id: inserted_person.id, - post_id: inserted_post.id, score: 1, }; @@ -121,7 +120,6 @@ mod tests { let child_comment_like = CommentLikeForm { comment_id: inserted_child_comment.id, person_id: another_inserted_person.id, - post_id: inserted_post.id, score: 1, }; From 7acfbbe5591d15019240e5d6bb3eca47b159776b Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 27 May 2024 20:51:04 -0700 Subject: [PATCH 08/21] Update comment.rs --- crates/db_schema/src/impls/comment.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/db_schema/src/impls/comment.rs b/crates/db_schema/src/impls/comment.rs index eff7da26f..bff5f6e15 100644 --- a/crates/db_schema/src/impls/comment.rs +++ b/crates/db_schema/src/impls/comment.rs @@ -296,7 +296,6 @@ mod tests { // Comment Like let comment_like_form = CommentLikeForm { comment_id: inserted_comment.id, - post_id: inserted_post.id, person_id: inserted_person.id, score: 1, }; @@ -305,7 +304,6 @@ mod tests { let expected_comment_like = CommentLike { comment_id: inserted_comment.id, - post_id: inserted_post.id, person_id: inserted_person.id, published: inserted_comment_like.published, score: 1, From cdddded0ae41d20e9b5645f61d51f919d8f930ae Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 27 May 2024 20:51:41 -0700 Subject: [PATCH 09/21] Update structs.rs --- crates/db_schema/src/aggregates/structs.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/db_schema/src/aggregates/structs.rs b/crates/db_schema/src/aggregates/structs.rs index fd7f70409..188ea41fd 100644 --- a/crates/db_schema/src/aggregates/structs.rs +++ b/crates/db_schema/src/aggregates/structs.rs @@ -173,7 +173,6 @@ pub struct PersonPostAggregatesForm { pub person_id: PersonId, pub post_id: PostId, pub read_comments: i64, - pub published: Option>, } #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone, Copy, Hash)] From d77b1721780a20368236d4f3476e673597451176 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 27 May 2024 20:52:30 -0700 Subject: [PATCH 10/21] Update comment.rs --- crates/db_schema/src/source/comment.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/db_schema/src/source/comment.rs b/crates/db_schema/src/source/comment.rs index 74ae0b7f6..6232c5eb6 100644 --- a/crates/db_schema/src/source/comment.rs +++ b/crates/db_schema/src/source/comment.rs @@ -99,7 +99,6 @@ pub struct CommentUpdateForm { pub struct CommentLike { pub person_id: PersonId, pub comment_id: CommentId, - pub post_id: PostId, // TODO this is redundant pub score: i16, pub published: DateTime, } @@ -110,7 +109,6 @@ pub struct CommentLike { pub struct CommentLikeForm { pub person_id: PersonId, pub comment_id: CommentId, - pub post_id: PostId, // TODO this is redundant pub score: i16, } From d4a8c3ddc1ee3408e24260cb0ed968dafd7860c1 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 27 May 2024 20:56:09 -0700 Subject: [PATCH 11/21] Create up.sql --- migrations/2024-03-16-134311_remove_redundant_post_id/up.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 migrations/2024-03-16-134311_remove_redundant_post_id/up.sql diff --git a/migrations/2024-03-16-134311_remove_redundant_post_id/up.sql b/migrations/2024-03-16-134311_remove_redundant_post_id/up.sql new file mode 100644 index 000000000..ea3a98aaf --- /dev/null +++ b/migrations/2024-03-16-134311_remove_redundant_post_id/up.sql @@ -0,0 +1,3 @@ +ALTER TABLE comment_like + DROP COLUMN post_id; + From 9efbb58b5f7089c409b78f994f5629c4b6c7bda2 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 27 May 2024 21:00:01 -0700 Subject: [PATCH 12/21] Create down.sql --- .../down.sql | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 migrations/2024-03-16-134311_remove_redundant_post_id/down.sql diff --git a/migrations/2024-03-16-134311_remove_redundant_post_id/down.sql b/migrations/2024-03-16-134311_remove_redundant_post_id/down.sql new file mode 100644 index 000000000..13fcacafb --- /dev/null +++ b/migrations/2024-03-16-134311_remove_redundant_post_id/down.sql @@ -0,0 +1,17 @@ +ALTER TABLE comment_like + ADD COLUMN post_id int REFERENCES post ON UPDATE CASCADE ON DELETE CASCADE; + +UPDATE + comment_like +SET + post_id = ( + SELECT + post_id + FROM + comment + WHERE + comment.id = comment_like.comment_id); + +ALTER TABLE comment_like + ALTER COLUMN post_id SET NOT NULL; + From 7c2c36191eb029dad3e91486a48d88dcc2a5b63e Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 27 May 2024 21:13:30 -0700 Subject: [PATCH 13/21] Update vote_view.rs --- crates/db_views/src/vote_view.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/db_views/src/vote_view.rs b/crates/db_views/src/vote_view.rs index a0441ff4e..ea1203192 100644 --- a/crates/db_views/src/vote_view.rs +++ b/crates/db_views/src/vote_view.rs @@ -10,7 +10,7 @@ use diesel::{ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::{CommentId, PostId}, - schema::{comment_like, community_person_ban, person, post, post_like}, + schema::{comment, comment_like, community_person_ban, person, post, post_like}, utils::{get_conn, limit_and_offset, DbPool}, }; @@ -59,7 +59,7 @@ impl VoteView { comment_like::table .inner_join(person::table) - .inner_join(post::table) + .inner_join(comment::table.inner_join(post::table)) // Join to community_person_ban to get creator_banned_from_community .left_join( community_person_ban::table.on( From 326e615ed0e51a16c720dc553ba2681220667856 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 28 May 2024 07:36:13 -0700 Subject: [PATCH 14/21] Update like.rs --- crates/api/src/comment/like.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/api/src/comment/like.rs b/crates/api/src/comment/like.rs index aa76b91e6..cbd86a5c4 100644 --- a/crates/api/src/comment/like.rs +++ b/crates/api/src/comment/like.rs @@ -1,4 +1,4 @@ -use activitypub_federation::config::Data; +use activitypub_federation::config::Data;p use actix_web::web::Json; use lemmy_api_common::{ build_response::build_comment_response, From 1bb6bd3c9e3245b9308782ed7ac80dddab6c6389 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 28 May 2024 07:36:26 -0700 Subject: [PATCH 15/21] Update like.rs --- crates/api/src/comment/like.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/api/src/comment/like.rs b/crates/api/src/comment/like.rs index cbd86a5c4..aa76b91e6 100644 --- a/crates/api/src/comment/like.rs +++ b/crates/api/src/comment/like.rs @@ -1,4 +1,4 @@ -use activitypub_federation::config::Data;p +use activitypub_federation::config::Data; use actix_web::web::Json; use lemmy_api_common::{ build_response::build_comment_response, From 0cfaa32b7860a5a3658ea0fa21cd68634e30471f Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 28 May 2024 08:05:17 -0700 Subject: [PATCH 16/21] Update comment_view.rs --- crates/db_views/src/comment_view.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 7588943b9..d3c251cc1 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -625,7 +625,6 @@ mod tests { let comment_like_form = CommentLikeForm { comment_id: inserted_comment_0.id, - post_id: inserted_post.id, person_id: inserted_timmy_person.id, score: 1, }; @@ -725,7 +724,6 @@ mod tests { // Like a new comment let comment_like_form = CommentLikeForm { comment_id: data.inserted_comment_1.id, - post_id: data.inserted_post.id, person_id: data.timmy_local_user_view.person.id, score: 1, }; From 603d27e2b9646ae41316d6810a8b2fe1f170583e Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 28 May 2024 08:06:04 -0700 Subject: [PATCH 17/21] Update vote_view.rs --- crates/db_views/src/vote_view.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/db_views/src/vote_view.rs b/crates/db_views/src/vote_view.rs index ea1203192..b31138fe2 100644 --- a/crates/db_views/src/vote_view.rs +++ b/crates/db_views/src/vote_view.rs @@ -189,7 +189,6 @@ mod tests { // Timothy votes down his own comment let timmy_comment_vote_form = CommentLikeForm { - post_id: inserted_post.id, comment_id: inserted_comment.id, person_id: inserted_timmy.id, score: -1, @@ -200,7 +199,6 @@ mod tests { // Sara upvotes timmy's comment let sara_comment_vote_form = CommentLikeForm { - post_id: inserted_post.id, comment_id: inserted_comment.id, person_id: inserted_sara.id, score: 1, From cb35bef3c415ddaee6228a9155cbfb92a682d3c5 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Wed, 5 Jun 2024 07:57:28 -0700 Subject: [PATCH 18/21] Rename down.sql to down.sql --- .../down.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename migrations/{2024-03-16-134311_remove_redundant_post_id => 2024-06-05-134311_remove_redundant_post_id}/down.sql (100%) diff --git a/migrations/2024-03-16-134311_remove_redundant_post_id/down.sql b/migrations/2024-06-05-134311_remove_redundant_post_id/down.sql similarity index 100% rename from migrations/2024-03-16-134311_remove_redundant_post_id/down.sql rename to migrations/2024-06-05-134311_remove_redundant_post_id/down.sql From 418844222b842640a93743d30f46c10f7e16e215 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Wed, 5 Jun 2024 07:58:12 -0700 Subject: [PATCH 19/21] Rename up.sql to up.sql --- .../up.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename migrations/{2024-03-16-134311_remove_redundant_post_id => 2024-06-05-134311_remove_redundant_post_id}/up.sql (100%) diff --git a/migrations/2024-03-16-134311_remove_redundant_post_id/up.sql b/migrations/2024-06-05-134311_remove_redundant_post_id/up.sql similarity index 100% rename from migrations/2024-03-16-134311_remove_redundant_post_id/up.sql rename to migrations/2024-06-05-134311_remove_redundant_post_id/up.sql From 8883f776c88bcdbf8677cda0526cdc5bff4de73c Mon Sep 17 00:00:00 2001 From: dullbananas Date: Wed, 5 Jun 2024 07:58:36 -0700 Subject: [PATCH 20/21] Update up.sql --- migrations/2024-06-05-134311_remove_redundant_post_id/up.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/2024-06-05-134311_remove_redundant_post_id/up.sql b/migrations/2024-06-05-134311_remove_redundant_post_id/up.sql index ea3a98aaf..012d7ab21 100644 --- a/migrations/2024-06-05-134311_remove_redundant_post_id/up.sql +++ b/migrations/2024-06-05-134311_remove_redundant_post_id/up.sql @@ -1,3 +1,3 @@ -ALTER TABLE comment_like +ALTER TABLE comment_actions DROP COLUMN post_id; From b7e8981d29779e59dad7a3ab95b87d1cf3282db9 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Wed, 5 Jun 2024 07:59:55 -0700 Subject: [PATCH 21/21] Update down.sql --- .../down.sql | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/migrations/2024-06-05-134311_remove_redundant_post_id/down.sql b/migrations/2024-06-05-134311_remove_redundant_post_id/down.sql index 13fcacafb..9c25a4872 100644 --- a/migrations/2024-06-05-134311_remove_redundant_post_id/down.sql +++ b/migrations/2024-06-05-134311_remove_redundant_post_id/down.sql @@ -1,8 +1,8 @@ -ALTER TABLE comment_like +ALTER TABLE comment_actions ADD COLUMN post_id int REFERENCES post ON UPDATE CASCADE ON DELETE CASCADE; UPDATE - comment_like + comment_actions SET post_id = ( SELECT @@ -10,8 +10,7 @@ SET FROM comment WHERE - comment.id = comment_like.comment_id); - -ALTER TABLE comment_like - ALTER COLUMN post_id SET NOT NULL; + comment.id = comment_actions.comment_id) +WHERE + liked IS NOT NULL;