From 925826170f044356e6780bcb6833ac9ab086ba6c Mon Sep 17 00:00:00 2001 From: Nutomic Date: Sat, 26 Oct 2024 20:45:12 +0200 Subject: [PATCH] Remove comment_like.post_id column which is unnecessary (ref #5122) (#5134) --- crates/api/src/comment/like.rs | 1 - crates/api_crud/src/comment/create.rs | 1 - .../src/activities/create_or_update/comment.rs | 1 - crates/apub/src/activities/voting/mod.rs | 1 - .../src/aggregates/comment_aggregates.rs | 2 -- .../db_schema/src/aggregates/person_aggregates.rs | 2 -- crates/db_schema/src/impls/comment.rs | 2 -- crates/db_schema/src/schema.rs | 2 -- crates/db_schema/src/source/comment.rs | 2 -- crates/db_views/src/comment_view.rs | 2 -- crates/db_views/src/vote_view.rs | 7 +++---- .../down.sql | 15 +++++++++++++++ .../up.sql | 3 +++ 13 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 migrations/2024-10-23-091053_comment-vote-remote-postid/down.sql create mode 100644 migrations/2024-10-23-091053_comment-vote-remote-postid/up.sql diff --git a/crates/api/src/comment/like.rs b/crates/api/src/comment/like.rs index 749b90426..e93b8513f 100644 --- a/crates/api/src/comment/like.rs +++ b/crates/api/src/comment/like.rs @@ -67,7 +67,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, }; diff --git a/crates/api_crud/src/comment/create.rs b/crates/api_crud/src/comment/create.rs index f85a4d929..2f67fa7e7 100644 --- a/crates/api_crud/src/comment/create.rs +++ b/crates/api_crud/src/comment/create.rs @@ -132,7 +132,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, }; diff --git a/crates/apub/src/activities/create_or_update/comment.rs b/crates/apub/src/activities/create_or_update/comment.rs index b2c436049..0a0737151 100644 --- a/crates/apub/src/activities/create_or_update/comment.rs +++ b/crates/apub/src/activities/create_or_update/comment.rs @@ -153,7 +153,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, }; 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(), }; diff --git a/crates/db_schema/src/aggregates/comment_aggregates.rs b/crates/db_schema/src/aggregates/comment_aggregates.rs index fc825ec99..a97bb565b 100644 --- a/crates/db_schema/src/aggregates/comment_aggregates.rs +++ b/crates/db_schema/src/aggregates/comment_aggregates.rs @@ -96,7 +96,6 @@ mod tests { let comment_like = CommentLikeForm { comment_id: inserted_comment.id, - post_id: inserted_post.id, person_id: inserted_person.id, score: 1, }; @@ -112,7 +111,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, }; diff --git a/crates/db_schema/src/aggregates/person_aggregates.rs b/crates/db_schema/src/aggregates/person_aggregates.rs index c68c90b0d..6e0eacc07 100644 --- a/crates/db_schema/src/aggregates/person_aggregates.rs +++ b/crates/db_schema/src/aggregates/person_aggregates.rs @@ -82,7 +82,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, }; @@ -99,7 +98,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, }; diff --git a/crates/db_schema/src/impls/comment.rs b/crates/db_schema/src/impls/comment.rs index ec246c121..30d18465f 100644 --- a/crates/db_schema/src/impls/comment.rs +++ b/crates/db_schema/src/impls/comment.rs @@ -289,7 +289,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, }; @@ -298,7 +297,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, diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 5534c4f60..2a8bfd150 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -123,7 +123,6 @@ diesel::table! { comment_like (person_id, comment_id) { person_id -> Int4, comment_id -> Int4, - post_id -> Int4, score -> Int2, published -> Timestamptz, } @@ -999,7 +998,6 @@ diesel::joinable!(comment -> post (post_id)); diesel::joinable!(comment_aggregates -> comment (comment_id)); diesel::joinable!(comment_like -> comment (comment_id)); diesel::joinable!(comment_like -> person (person_id)); -diesel::joinable!(comment_like -> post (post_id)); diesel::joinable!(comment_reply -> comment (comment_id)); diesel::joinable!(comment_reply -> person (recipient_id)); diesel::joinable!(comment_report -> comment (comment_id)); diff --git a/crates/db_schema/src/source/comment.rs b/crates/db_schema/src/source/comment.rs index e7d031c68..1e5f043f1 100644 --- a/crates/db_schema/src/source/comment.rs +++ b/crates/db_schema/src/source/comment.rs @@ -102,7 +102,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, } @@ -113,7 +112,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, } diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index dc9aceec0..55fea4d66 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -601,7 +601,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, }; @@ -701,7 +700,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, }; diff --git a/crates/db_views/src/vote_view.rs b/crates/db_views/src/vote_view.rs index 9c5fef855..0fd64deca 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,8 @@ impl VoteView { comment_like::table .inner_join(person::table) - .inner_join(post::table) + .inner_join(comment::table) + .inner_join(post::table.on(comment::post_id.eq(post::id))) // Join to community_person_ban to get creator_banned_from_community .left_join( community_person_ban::table.on( @@ -173,7 +174,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, @@ -182,7 +182,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, diff --git a/migrations/2024-10-23-091053_comment-vote-remote-postid/down.sql b/migrations/2024-10-23-091053_comment-vote-remote-postid/down.sql new file mode 100644 index 000000000..21c730af3 --- /dev/null +++ b/migrations/2024-10-23-091053_comment-vote-remote-postid/down.sql @@ -0,0 +1,15 @@ +ALTER TABLE comment_like + ADD COLUMN post_id int; + +UPDATE + comment_like +SET + post_id = comment.post_id +FROM + comment +WHERE + comment_id = comment.id; + +ALTER TABLE comment_like + ALTER COLUMN post_id SET NOT NULL; + diff --git a/migrations/2024-10-23-091053_comment-vote-remote-postid/up.sql b/migrations/2024-10-23-091053_comment-vote-remote-postid/up.sql new file mode 100644 index 000000000..f6cbf3639 --- /dev/null +++ b/migrations/2024-10-23-091053_comment-vote-remote-postid/up.sql @@ -0,0 +1,3 @@ +ALTER TABLE comment_like + DROP post_id; +