diff --git a/crates/db_schema/src/lib.rs b/crates/db_schema/src/lib.rs index 5b908f356..1aa0e4e88 100644 --- a/crates/db_schema/src/lib.rs +++ b/crates/db_schema/src/lib.rs @@ -30,8 +30,8 @@ pub mod newtypes; pub mod schema; #[cfg(feature = "full")] pub mod aliases { - use crate::schema::person; - diesel::alias!(person as person1: Person1, person as person2: Person2); + use crate::schema::{community_moderator, person}; + diesel::alias!(person as person1: Person1, person as person2: Person2, community_moderator as community_moderator1: CommunityModerator1); } pub mod source; #[cfg(feature = "full")] diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 4fe037594..b48962a23 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -12,6 +12,7 @@ use diesel::{ use diesel_async::RunQueryDsl; use diesel_ltree::{nlevel, subpath, Ltree, LtreeExtensions}; use lemmy_db_schema::{ + aliases, newtypes::{CommentId, CommunityId, LocalUserId, PersonId, PostId}, schema::{ comment, @@ -54,13 +55,6 @@ fn queries<'a>() -> Queries< .and(community_person_ban::person_id.eq(comment::creator_id)), ), ) - .left_join( - community_moderator::table.on( - community::id - .eq(community_moderator::community_id) - .and(community_moderator::person_id.eq(comment::creator_id)), - ), - ) .left_join( community_follower::table.on( post::community_id @@ -89,6 +83,25 @@ fn queries<'a>() -> Queries< .and(comment_like::person_id.eq(person_id_join)), ), ) + .left_join( + community_moderator::table.on( + post::id + .eq(comment::post_id) + .and(post::community_id.eq(community_moderator::community_id)) + .and(community_moderator::person_id.eq(person_id_join)), + ), + ) + .left_join( + aliases::community_moderator1.on( + community::id + .eq(aliases::community_moderator1.field(community_moderator::community_id)) + .and( + aliases::community_moderator1 + .field(community_moderator::person_id) + .eq(comment::creator_id), + ), + ), + ) }; let selection = ( @@ -98,7 +111,10 @@ fn queries<'a>() -> Queries< community::all_columns, comment_aggregates::all_columns, community_person_ban::id.nullable().is_not_null(), - community_moderator::id.nullable().is_not_null(), + aliases::community_moderator1 + .field(community_moderator::id) + .nullable() + .is_not_null(), CommunityFollower::select_subscribed_type(), comment_saved::id.nullable().is_not_null(), person_block::id.nullable().is_not_null(),