diff --git a/crates/db_schema/src/impls/person.rs b/crates/db_schema/src/impls/person.rs index dc283c389b..de99d4b63d 100644 --- a/crates/db_schema/src/impls/person.rs +++ b/crates/db_schema/src/impls/person.rs @@ -66,108 +66,6 @@ mod safe_type { } } -mod safe_type_alias_1 { - use crate::{schema::person_alias_1::columns::*, source::person::PersonAlias1, traits::ToSafe}; - - type Columns = ( - id, - name, - display_name, - avatar, - banned, - published, - updated, - actor_id, - bio, - local, - banner, - deleted, - inbox_url, - shared_inbox_url, - matrix_user_id, - admin, - bot_account, - ban_expires, - ); - - impl ToSafe for PersonAlias1 { - type SafeColumns = Columns; - fn safe_columns_tuple() -> Self::SafeColumns { - ( - id, - name, - display_name, - avatar, - banned, - published, - updated, - actor_id, - bio, - local, - banner, - deleted, - inbox_url, - shared_inbox_url, - matrix_user_id, - admin, - bot_account, - ban_expires, - ) - } - } -} - -mod safe_type_alias_2 { - use crate::{schema::person_alias_2::columns::*, source::person::PersonAlias2, traits::ToSafe}; - - type Columns = ( - id, - name, - display_name, - avatar, - banned, - published, - updated, - actor_id, - bio, - local, - banner, - deleted, - inbox_url, - shared_inbox_url, - matrix_user_id, - admin, - bot_account, - ban_expires, - ); - - impl ToSafe for PersonAlias2 { - type SafeColumns = Columns; - fn safe_columns_tuple() -> Self::SafeColumns { - ( - id, - name, - display_name, - avatar, - banned, - published, - updated, - actor_id, - bio, - local, - banner, - deleted, - inbox_url, - shared_inbox_url, - matrix_user_id, - admin, - bot_account, - ban_expires, - ) - } - } -} - impl Crud for Person { type Form = PersonForm; type IdType = PersonId; diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 2d6ff6124e..e0d7167e7b 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -531,59 +531,6 @@ table! { } } -// These are necessary since diesel doesn't have self joins / aliases -table! { - person_alias_1 (id) { - id -> Int4, - name -> Varchar, - display_name -> Nullable, - avatar -> Nullable, - banned -> Bool, - published -> Timestamp, - updated -> Nullable, - actor_id -> Varchar, - bio -> Nullable, - local -> Bool, - private_key -> Nullable, - public_key -> Text, - last_refreshed_at -> Timestamp, - banner -> Nullable, - deleted -> Bool, - inbox_url -> Varchar, - shared_inbox_url -> Nullable, - matrix_user_id -> Nullable, - admin -> Bool, - bot_account -> Bool, - ban_expires -> Nullable, - } -} - -table! { - person_alias_2 (id) { - id -> Int4, - name -> Varchar, - display_name -> Nullable, - avatar -> Nullable, - banned -> Bool, - published -> Timestamp, - updated -> Nullable, - actor_id -> Varchar, - bio -> Nullable, - local -> Bool, - private_key -> Nullable, - public_key -> Text, - last_refreshed_at -> Timestamp, - banner -> Nullable, - deleted -> Bool, - inbox_url -> Varchar, - shared_inbox_url -> Nullable, - matrix_user_id -> Nullable, - admin -> Bool, - bot_account -> Bool, - ban_expires -> Nullable, - } -} - table! { secret(id) { id -> Int4, @@ -677,18 +624,7 @@ table! { } } -joinable!(person_mention -> person_alias_1 (recipient_id)); -joinable!(comment_reply -> person_alias_1 (recipient_id)); -joinable!(post -> person_alias_1 (creator_id)); -joinable!(comment -> person_alias_1 (creator_id)); -joinable!(private_message_report -> person_alias_1 (resolver_id)); - -joinable!(post_report -> person_alias_2 (resolver_id)); -joinable!(comment_report -> person_alias_2 (resolver_id)); -joinable!(private_message_report -> person_alias_2 (resolver_id)); - joinable!(person_block -> person (person_id)); -joinable!(person_block -> person_alias_1 (target_id)); joinable!(comment -> person (creator_id)); joinable!(comment -> post (post_id)); @@ -800,8 +736,6 @@ allow_tables_to_appear_in_same_query!( private_message_report, site, site_aggregates, - person_alias_1, - person_alias_2, admin_purge_comment, admin_purge_community, admin_purge_person, diff --git a/crates/db_schema/src/source/person.rs b/crates/db_schema/src/source/person.rs index 36882c96ea..5d9d603de8 100644 --- a/crates/db_schema/src/source/person.rs +++ b/crates/db_schema/src/source/person.rs @@ -2,7 +2,7 @@ use crate::newtypes::{DbUrl, PersonId}; use serde::{Deserialize, Serialize}; #[cfg(feature = "full")] -use crate::schema::{person, person_alias_1, person_alias_2}; +use crate::schema::person; #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] #[cfg_attr(feature = "full", derive(Queryable, Identifiable))] @@ -56,108 +56,6 @@ pub struct PersonSafe { pub ban_expires: Option, } -#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] -#[cfg_attr(feature = "full", diesel(table_name = person_alias_1))] -pub struct PersonAlias1 { - pub id: PersonId, - pub name: String, - pub display_name: Option, - pub avatar: Option, - pub banned: bool, - pub published: chrono::NaiveDateTime, - pub updated: Option, - pub actor_id: DbUrl, - pub bio: Option, - pub local: bool, - pub private_key: Option, - pub public_key: String, - pub last_refreshed_at: chrono::NaiveDateTime, - pub banner: Option, - pub deleted: bool, - pub inbox_url: DbUrl, - pub shared_inbox_url: Option, - pub matrix_user_id: Option, - pub admin: bool, - pub bot_account: bool, - pub ban_expires: Option, -} - -#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] -#[cfg_attr(feature = "full", diesel(table_name = person_alias_1))] -pub struct PersonSafeAlias1 { - pub id: PersonId, - pub name: String, - pub display_name: Option, - pub avatar: Option, - pub banned: bool, - pub published: chrono::NaiveDateTime, - pub updated: Option, - pub actor_id: DbUrl, - pub bio: Option, - pub local: bool, - pub banner: Option, - pub deleted: bool, - pub inbox_url: DbUrl, - pub shared_inbox_url: Option, - pub matrix_user_id: Option, - pub admin: bool, - pub bot_account: bool, - pub ban_expires: Option, -} - -#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] -#[cfg_attr(feature = "full", diesel(table_name = person_alias_2))] -pub struct PersonAlias2 { - pub id: PersonId, - pub name: String, - pub display_name: Option, - pub avatar: Option, - pub banned: bool, - pub published: chrono::NaiveDateTime, - pub updated: Option, - pub actor_id: DbUrl, - pub bio: Option, - pub local: bool, - pub private_key: Option, - pub public_key: String, - pub last_refreshed_at: chrono::NaiveDateTime, - pub banner: Option, - pub deleted: bool, - pub inbox_url: DbUrl, - pub shared_inbox_url: Option, - pub matrix_user_id: Option, - pub admin: bool, - pub bot_account: bool, - pub ban_expires: Option, -} - -#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] -#[cfg_attr(feature = "full", diesel(table_name = person_alias_1))] -pub struct PersonSafeAlias2 { - pub id: PersonId, - pub name: String, - pub display_name: Option, - pub avatar: Option, - pub banned: bool, - pub published: chrono::NaiveDateTime, - pub updated: Option, - pub actor_id: DbUrl, - pub bio: Option, - pub local: bool, - pub banner: Option, - pub deleted: bool, - pub inbox_url: DbUrl, - pub shared_inbox_url: Option, - pub matrix_user_id: Option, - pub admin: bool, - pub bot_account: bool, - pub ban_expires: Option, -} - #[derive(Clone, Default)] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = person))] diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index 99447da357..50564b0ab7 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -12,15 +12,13 @@ use lemmy_db_schema::{ community_moderator, community_person_ban, person, - person_alias_1, - person_alias_2, post, }, source::{ comment::Comment, comment_report::CommentReport, community::{Community, CommunityPersonBan, CommunitySafe}, - person::{Person, PersonAlias1, PersonAlias2, PersonSafe, PersonSafeAlias1, PersonSafeAlias2}, + person::{Person, PersonSafe}, post::Post, }, traits::{ToSafe, ViewToVec}, @@ -34,11 +32,11 @@ type CommentReportViewTuple = ( Post, CommunitySafe, PersonSafe, - PersonSafeAlias1, + PersonSafe, CommentAggregates, Option, Option, - Option, + Option, ); impl CommentReportView { @@ -50,6 +48,8 @@ impl CommentReportView { report_id: CommentReportId, my_person_id: PersonId, ) -> Result { + let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2); + let ( comment_report, comment, @@ -67,7 +67,7 @@ impl CommentReportView { .inner_join(post::table.on(comment::post_id.eq(post::id))) .inner_join(community::table.on(post::community_id.eq(community::id))) .inner_join(person::table.on(comment_report::creator_id.eq(person::id))) - .inner_join(person_alias_1::table.on(comment::creator_id.eq(person_alias_1::id))) + .inner_join(person_alias_1.on(comment::creator_id.eq(person_alias_1.field(person::id)))) .inner_join( comment_aggregates::table.on(comment_report::comment_id.eq(comment_aggregates::comment_id)), ) @@ -91,7 +91,8 @@ impl CommentReportView { ), ) .left_join( - person_alias_2::table.on(comment_report::resolver_id.eq(person_alias_2::id.nullable())), + person_alias_2 + .on(comment_report::resolver_id.eq(person_alias_2.field(person::id).nullable())), ) .select(( comment_report::all_columns, @@ -99,11 +100,13 @@ impl CommentReportView { post::all_columns, Community::safe_columns_tuple(), Person::safe_columns_tuple(), - PersonAlias1::safe_columns_tuple(), + person_alias_1.fields(Person::safe_columns_tuple()), comment_aggregates::all_columns, community_person_ban::all_columns.nullable(), comment_like::score.nullable(), - PersonAlias2::safe_columns_tuple().nullable(), + person_alias_2 + .fields(Person::safe_columns_tuple()) + .nullable(), )) .first::(conn)?; @@ -177,12 +180,14 @@ pub struct CommentReportQuery<'a> { impl<'a> CommentReportQuery<'a> { pub fn list(self) -> Result, Error> { + let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2); + let mut query = comment_report::table .inner_join(comment::table) .inner_join(post::table.on(comment::post_id.eq(post::id))) .inner_join(community::table.on(post::community_id.eq(community::id))) .inner_join(person::table.on(comment_report::creator_id.eq(person::id))) - .inner_join(person_alias_1::table.on(comment::creator_id.eq(person_alias_1::id))) + .inner_join(person_alias_1.on(comment::creator_id.eq(person_alias_1.field(person::id)))) .inner_join( comment_aggregates::table.on(comment_report::comment_id.eq(comment_aggregates::comment_id)), ) @@ -206,7 +211,8 @@ impl<'a> CommentReportQuery<'a> { ), ) .left_join( - person_alias_2::table.on(comment_report::resolver_id.eq(person_alias_2::id.nullable())), + person_alias_2 + .on(comment_report::resolver_id.eq(person_alias_2.field(person::id).nullable())), ) .select(( comment_report::all_columns, @@ -214,11 +220,13 @@ impl<'a> CommentReportQuery<'a> { post::all_columns, Community::safe_columns_tuple(), Person::safe_columns_tuple(), - PersonAlias1::safe_columns_tuple(), + person_alias_1.fields(Person::safe_columns_tuple()), comment_aggregates::all_columns, community_person_ban::all_columns.nullable(), comment_like::score.nullable(), - PersonAlias2::safe_columns_tuple().nullable(), + person_alias_2 + .fields(Person::safe_columns_tuple()) + .nullable(), )) .into_boxed(); @@ -418,7 +426,7 @@ mod tests { matrix_user_id: None, ban_expires: None, }, - comment_creator: PersonSafeAlias1 { + comment_creator: PersonSafe { id: inserted_timmy.id, name: inserted_timmy.name.to_owned(), display_name: None, @@ -516,7 +524,7 @@ mod tests { .updated = read_jessica_report_view_after_resolve .comment_report .updated; - expected_jessica_report_view_after_resolve.resolver = Some(PersonSafeAlias2 { + expected_jessica_report_view_after_resolve.resolver = Some(PersonSafe { id: inserted_timmy.id, name: inserted_timmy.name.to_owned(), display_name: None, diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index 9c4ab612ce..472795b504 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -8,8 +8,6 @@ use lemmy_db_schema::{ community_moderator, community_person_ban, person, - person_alias_1, - person_alias_2, post, post_aggregates, post_like, @@ -17,7 +15,7 @@ use lemmy_db_schema::{ }, source::{ community::{Community, CommunityPersonBan, CommunitySafe}, - person::{Person, PersonAlias1, PersonAlias2, PersonSafe, PersonSafeAlias1, PersonSafeAlias2}, + person::{Person, PersonSafe}, post::Post, post_report::PostReport, }, @@ -31,11 +29,11 @@ type PostReportViewTuple = ( Post, CommunitySafe, PersonSafe, - PersonSafeAlias1, + PersonSafe, Option, Option, PostAggregates, - Option, + Option, ); impl PostReportView { @@ -47,6 +45,8 @@ impl PostReportView { report_id: PostReportId, my_person_id: PersonId, ) -> Result { + let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2); + let ( post_report, post, @@ -62,7 +62,7 @@ impl PostReportView { .inner_join(post::table) .inner_join(community::table.on(post::community_id.eq(community::id))) .inner_join(person::table.on(post_report::creator_id.eq(person::id))) - .inner_join(person_alias_1::table.on(post::creator_id.eq(person_alias_1::id))) + .inner_join(person_alias_1.on(post::creator_id.eq(person_alias_1.field(person::id)))) .left_join( community_person_ban::table.on( post::community_id @@ -84,18 +84,18 @@ impl PostReportView { ) .inner_join(post_aggregates::table.on(post_report::post_id.eq(post_aggregates::post_id))) .left_join( - person_alias_2::table.on(post_report::resolver_id.eq(person_alias_2::id.nullable())), + person_alias_2.on(post_report::resolver_id.eq(person_alias_2.field(person::id).nullable())), ) .select(( post_report::all_columns, post::all_columns, Community::safe_columns_tuple(), Person::safe_columns_tuple(), - PersonAlias1::safe_columns_tuple(), + person_alias_1.fields(Person::safe_columns_tuple()), community_person_ban::all_columns.nullable(), post_like::score.nullable(), post_aggregates::all_columns, - PersonAlias2::safe_columns_tuple().nullable(), + person_alias_2.fields(Person::safe_columns_tuple().nullable()), )) .first::(conn)?; @@ -166,11 +166,13 @@ pub struct PostReportQuery<'a> { impl<'a> PostReportQuery<'a> { pub fn list(self) -> Result, Error> { + let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2); + let mut query = post_report::table .inner_join(post::table) .inner_join(community::table.on(post::community_id.eq(community::id))) .inner_join(person::table.on(post_report::creator_id.eq(person::id))) - .inner_join(person_alias_1::table.on(post::creator_id.eq(person_alias_1::id))) + .inner_join(person_alias_1.on(post::creator_id.eq(person_alias_1.field(person::id)))) .left_join( community_person_ban::table.on( post::community_id @@ -192,18 +194,20 @@ impl<'a> PostReportQuery<'a> { ) .inner_join(post_aggregates::table.on(post_report::post_id.eq(post_aggregates::post_id))) .left_join( - person_alias_2::table.on(post_report::resolver_id.eq(person_alias_2::id.nullable())), + person_alias_2.on(post_report::resolver_id.eq(person_alias_2.field(person::id).nullable())), ) .select(( post_report::all_columns, post::all_columns, Community::safe_columns_tuple(), Person::safe_columns_tuple(), - PersonAlias1::safe_columns_tuple(), + person_alias_1.fields(Person::safe_columns_tuple()), community_person_ban::all_columns.nullable(), post_like::score.nullable(), post_aggregates::all_columns, - PersonAlias2::safe_columns_tuple().nullable(), + person_alias_2 + .fields(Person::safe_columns_tuple()) + .nullable(), )) .into_boxed(); @@ -401,7 +405,7 @@ mod tests { matrix_user_id: None, ban_expires: None, }, - post_creator: PersonSafeAlias1 { + post_creator: PersonSafe { id: inserted_timmy.id, name: inserted_timmy.name.to_owned(), display_name: None, @@ -501,7 +505,7 @@ mod tests { expected_jessica_report_view_after_resolve .post_report .updated = read_jessica_report_view_after_resolve.post_report.updated; - expected_jessica_report_view_after_resolve.resolver = Some(PersonSafeAlias2 { + expected_jessica_report_view_after_resolve.resolver = Some(PersonSafe { id: inserted_timmy.id, name: inserted_timmy.name.to_owned(), display_name: None, diff --git a/crates/db_views/src/private_message_report_view.rs b/crates/db_views/src/private_message_report_view.rs index a5a2b1b42d..9a5976847b 100644 --- a/crates/db_views/src/private_message_report_view.rs +++ b/crates/db_views/src/private_message_report_view.rs @@ -2,9 +2,9 @@ use crate::structs::PrivateMessageReportView; use diesel::{result::Error, *}; use lemmy_db_schema::{ newtypes::PrivateMessageReportId, - schema::{person, person_alias_1, person_alias_2, private_message, private_message_report}, + schema::{person, private_message, private_message_report}, source::{ - person::{Person, PersonAlias1, PersonAlias2, PersonSafe, PersonSafeAlias1, PersonSafeAlias2}, + person::{Person, PersonSafe}, private_message::PrivateMessage, private_message_report::PrivateMessageReport, }, @@ -17,8 +17,8 @@ type PrivateMessageReportViewTuple = ( PrivateMessageReport, PrivateMessage, PersonSafe, - PersonSafeAlias1, - Option, + PersonSafe, + Option, ); impl PrivateMessageReportView { @@ -26,24 +26,30 @@ impl PrivateMessageReportView { /// /// * `report_id` - the report id to obtain pub fn read(conn: &mut PgConnection, report_id: PrivateMessageReportId) -> Result { + let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2); + let (private_message_report, private_message, private_message_creator, creator, resolver) = private_message_report::table .find(report_id) .inner_join(private_message::table) .inner_join(person::table.on(private_message::creator_id.eq(person::id))) .inner_join( - person_alias_1::table.on(private_message_report::creator_id.eq(person_alias_1::id)), + person_alias_1 + .on(private_message_report::creator_id.eq(person_alias_1.field(person::id))), ) .left_join( - person_alias_2::table - .on(private_message_report::resolver_id.eq(person_alias_2::id.nullable())), + person_alias_2.on( + private_message_report::resolver_id.eq(person_alias_2.field(person::id).nullable()), + ), ) .select(( private_message_report::all_columns, private_message::all_columns, Person::safe_columns_tuple(), - PersonAlias1::safe_columns_tuple(), - PersonAlias2::safe_columns_tuple().nullable(), + person_alias_1.fields(Person::safe_columns_tuple()), + person_alias_2 + .fields(Person::safe_columns_tuple()) + .nullable(), )) .first::(conn)?; @@ -81,22 +87,26 @@ pub struct PrivateMessageReportQuery<'a> { impl<'a> PrivateMessageReportQuery<'a> { pub fn list(self) -> Result, Error> { + let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2); + let mut query = private_message_report::table .inner_join(private_message::table) .inner_join(person::table.on(private_message::creator_id.eq(person::id))) .inner_join( - person_alias_1::table.on(private_message_report::creator_id.eq(person_alias_1::id)), + person_alias_1.on(private_message_report::creator_id.eq(person_alias_1.field(person::id))), ) .left_join( - person_alias_2::table - .on(private_message_report::resolver_id.eq(person_alias_2::id.nullable())), + person_alias_2 + .on(private_message_report::resolver_id.eq(person_alias_2.field(person::id).nullable())), ) .select(( private_message_report::all_columns, private_message::all_columns, Person::safe_columns_tuple(), - PersonAlias1::safe_columns_tuple(), - PersonAlias2::safe_columns_tuple().nullable(), + person_alias_1.fields(Person::safe_columns_tuple()), + person_alias_2 + .fields(Person::safe_columns_tuple()) + .nullable(), )) .into_boxed(); diff --git a/crates/db_views/src/private_message_view.rs b/crates/db_views/src/private_message_view.rs index ff28f7ed0a..281df8ba6b 100644 --- a/crates/db_views/src/private_message_view.rs +++ b/crates/db_views/src/private_message_view.rs @@ -2,9 +2,9 @@ use crate::structs::PrivateMessageView; use diesel::{pg::Pg, result::Error, *}; use lemmy_db_schema::{ newtypes::{PersonId, PrivateMessageId}, - schema::{person, person_alias_1, private_message}, + schema::{person, private_message}, source::{ - person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1}, + person::{Person, PersonSafe}, private_message::PrivateMessage, }, traits::{ToSafe, ViewToVec}, @@ -13,22 +13,26 @@ use lemmy_db_schema::{ use tracing::debug; use typed_builder::TypedBuilder; -type PrivateMessageViewTuple = (PrivateMessage, PersonSafe, PersonSafeAlias1); +type PrivateMessageViewTuple = (PrivateMessage, PersonSafe, PersonSafe); impl PrivateMessageView { pub fn read( conn: &mut PgConnection, private_message_id: PrivateMessageId, ) -> Result { + let person_alias_1 = diesel::alias!(person as person1); + let (private_message, creator, recipient) = private_message::table .find(private_message_id) .inner_join(person::table.on(private_message::creator_id.eq(person::id))) - .inner_join(person_alias_1::table.on(private_message::recipient_id.eq(person_alias_1::id))) + .inner_join( + person_alias_1.on(private_message::recipient_id.eq(person_alias_1.field(person::id))), + ) .order_by(private_message::published.desc()) .select(( private_message::all_columns, Person::safe_columns_tuple(), - PersonAlias1::safe_columns_tuple(), + person_alias_1.fields(Person::safe_columns_tuple()), )) .first::(conn)?; @@ -68,13 +72,17 @@ pub struct PrivateMessageQuery<'a> { impl<'a> PrivateMessageQuery<'a> { pub fn list(self) -> Result, Error> { + let person_alias_1 = diesel::alias!(person as person1); + let mut query = private_message::table .inner_join(person::table.on(private_message::creator_id.eq(person::id))) - .inner_join(person_alias_1::table.on(private_message::recipient_id.eq(person_alias_1::id))) + .inner_join( + person_alias_1.on(private_message::recipient_id.eq(person_alias_1.field(person::id))), + ) .select(( private_message::all_columns, Person::safe_columns_tuple(), - PersonAlias1::safe_columns_tuple(), + person_alias_1.fields(Person::safe_columns_tuple()), )) .into_boxed(); diff --git a/crates/db_views/src/registration_application_view.rs b/crates/db_views/src/registration_application_view.rs index 6caa288ac5..b4c848293c 100644 --- a/crates/db_views/src/registration_application_view.rs +++ b/crates/db_views/src/registration_application_view.rs @@ -1,10 +1,10 @@ use crate::structs::RegistrationApplicationView; use diesel::{dsl::count, result::Error, *}; use lemmy_db_schema::{ - schema::{local_user, person, person_alias_1, registration_application}, + schema::{local_user, person, registration_application}, source::{ local_user::{LocalUser, LocalUserSettings}, - person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1}, + person::{Person, PersonSafe}, registration_application::RegistrationApplication, }, traits::{ToSafe, ToSafeSettings, ViewToVec}, @@ -16,11 +16,13 @@ type RegistrationApplicationViewTuple = ( RegistrationApplication, LocalUserSettings, PersonSafe, - Option, + Option, ); impl RegistrationApplicationView { pub fn read(conn: &mut PgConnection, registration_application_id: i32) -> Result { + let person_alias_1 = diesel::alias!(person as person1); + let (registration_application, creator_local_user, creator, admin) = registration_application::table .find(registration_application_id) @@ -29,15 +31,17 @@ impl RegistrationApplicationView { ) .inner_join(person::table.on(local_user::person_id.eq(person::id))) .left_join( - person_alias_1::table - .on(registration_application::admin_id.eq(person_alias_1::id.nullable())), + person_alias_1 + .on(registration_application::admin_id.eq(person_alias_1.field(person::id).nullable())), ) .order_by(registration_application::published.desc()) .select(( registration_application::all_columns, LocalUser::safe_settings_columns_tuple(), Person::safe_columns_tuple(), - PersonAlias1::safe_columns_tuple().nullable(), + person_alias_1 + .fields(Person::safe_columns_tuple()) + .nullable(), )) .first::(conn)?; @@ -54,12 +58,14 @@ impl RegistrationApplicationView { conn: &mut PgConnection, verified_email_only: bool, ) -> Result { + let person_alias_1 = diesel::alias!(person as person1); + let mut query = registration_application::table .inner_join(local_user::table.on(registration_application::local_user_id.eq(local_user::id))) .inner_join(person::table.on(local_user::person_id.eq(person::id))) .left_join( - person_alias_1::table - .on(registration_application::admin_id.eq(person_alias_1::id.nullable())), + person_alias_1 + .on(registration_application::admin_id.eq(person_alias_1.field(person::id).nullable())), ) .filter(registration_application::admin_id.is_null()) .into_boxed(); @@ -87,19 +93,23 @@ pub struct RegistrationApplicationQuery<'a> { impl<'a> RegistrationApplicationQuery<'a> { pub fn list(self) -> Result, Error> { + let person_alias_1 = diesel::alias!(person as person1); + let mut query = registration_application::table .inner_join(local_user::table.on(registration_application::local_user_id.eq(local_user::id))) .inner_join(person::table.on(local_user::person_id.eq(person::id))) .left_join( - person_alias_1::table - .on(registration_application::admin_id.eq(person_alias_1::id.nullable())), + person_alias_1 + .on(registration_application::admin_id.eq(person_alias_1.field(person::id).nullable())), ) .order_by(registration_application::published.desc()) .select(( registration_application::all_columns, LocalUser::safe_settings_columns_tuple(), Person::safe_columns_tuple(), - PersonAlias1::safe_columns_tuple().nullable(), + person_alias_1 + .fields(Person::safe_columns_tuple()) + .nullable(), )) .into_boxed(); @@ -324,7 +334,7 @@ mod tests { .accepted_application = true; expected_sara_app_view.registration_application.admin_id = Some(inserted_timmy_person.id); - expected_sara_app_view.admin = Some(PersonSafeAlias1 { + expected_sara_app_view.admin = Some(PersonSafe { id: inserted_timmy_person.id, name: inserted_timmy_person.name.to_owned(), display_name: None, diff --git a/crates/db_views/src/structs.rs b/crates/db_views/src/structs.rs index c22800266d..83f1e122d3 100644 --- a/crates/db_views/src/structs.rs +++ b/crates/db_views/src/structs.rs @@ -6,7 +6,7 @@ use lemmy_db_schema::{ community::CommunitySafe, language::Language, local_user::{LocalUser, LocalUserSettings}, - person::{Person, PersonSafe, PersonSafeAlias1, PersonSafeAlias2}, + person::{Person, PersonSafe}, post::Post, post_report::PostReport, private_message::PrivateMessage, @@ -25,11 +25,11 @@ pub struct CommentReportView { pub post: Post, pub community: CommunitySafe, pub creator: PersonSafe, - pub comment_creator: PersonSafeAlias1, + pub comment_creator: PersonSafe, pub counts: CommentAggregates, pub creator_banned_from_community: bool, // Left Join to CommunityPersonBan pub my_vote: Option, // Left join to CommentLike - pub resolver: Option, + pub resolver: Option, } #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] @@ -66,11 +66,11 @@ pub struct PostReportView { pub post: Post, pub community: CommunitySafe, pub creator: PersonSafe, - pub post_creator: PersonSafeAlias1, + pub post_creator: PersonSafe, pub creator_banned_from_community: bool, pub my_vote: Option, pub counts: PostAggregates, - pub resolver: Option, + pub resolver: Option, } #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] @@ -92,7 +92,7 @@ pub struct PostView { pub struct PrivateMessageView { pub private_message: PrivateMessage, pub creator: PersonSafe, - pub recipient: PersonSafeAlias1, + pub recipient: PersonSafe, } #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] @@ -100,8 +100,8 @@ pub struct PrivateMessageReportView { pub private_message_report: PrivateMessageReport, pub private_message: PrivateMessage, pub private_message_creator: PersonSafe, - pub creator: PersonSafeAlias1, - pub resolver: Option, + pub creator: PersonSafe, + pub resolver: Option, } #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] @@ -109,7 +109,7 @@ pub struct RegistrationApplicationView { pub registration_application: RegistrationApplication, pub creator_local_user: LocalUserSettings, pub creator: PersonSafe, - pub admin: Option, + pub admin: Option, } #[derive(Debug, Serialize, Deserialize, Clone)] diff --git a/crates/db_views_actor/src/comment_reply_view.rs b/crates/db_views_actor/src/comment_reply_view.rs index 78ede54e21..39ba74ccb2 100644 --- a/crates/db_views_actor/src/comment_reply_view.rs +++ b/crates/db_views_actor/src/comment_reply_view.rs @@ -13,7 +13,6 @@ use lemmy_db_schema::{ community_follower, community_person_ban, person, - person_alias_1, person_block, post, }, @@ -21,7 +20,7 @@ use lemmy_db_schema::{ comment::{Comment, CommentSaved}, comment_reply::CommentReply, community::{Community, CommunityFollower, CommunityPersonBan, CommunitySafe}, - person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1}, + person::{Person, PersonSafe}, person_block::PersonBlock, post::Post, }, @@ -37,7 +36,7 @@ type CommentReplyViewTuple = ( PersonSafe, Post, CommunitySafe, - PersonSafeAlias1, + PersonSafe, CommentAggregates, Option, Option, @@ -52,6 +51,8 @@ impl CommentReplyView { comment_reply_id: CommentReplyId, my_person_id: Option, ) -> Result { + let person_alias_1 = diesel::alias!(person as person1); + // The left join below will return None in this case let person_id_join = my_person_id.unwrap_or(PersonId(-1)); @@ -74,7 +75,7 @@ impl CommentReplyView { .inner_join(person::table.on(comment::creator_id.eq(person::id))) .inner_join(post::table.on(comment::post_id.eq(post::id))) .inner_join(community::table.on(post::community_id.eq(community::id))) - .inner_join(person_alias_1::table) + .inner_join(person_alias_1) .inner_join(comment_aggregates::table.on(comment::id.eq(comment_aggregates::comment_id))) .left_join( community_person_ban::table.on( @@ -122,7 +123,7 @@ impl CommentReplyView { Person::safe_columns_tuple(), post::all_columns, Community::safe_columns_tuple(), - PersonAlias1::safe_columns_tuple(), + person_alias_1.fields(Person::safe_columns_tuple()), comment_aggregates::all_columns, community_person_ban::all_columns.nullable(), community_follower::all_columns.nullable(), @@ -178,6 +179,8 @@ impl<'a> CommentReplyQuery<'a> { pub fn list(self) -> Result, Error> { use diesel::dsl::*; + let person_alias_1 = diesel::alias!(person as person1); + // The left join below will return None in this case let person_id_join = self.my_person_id.unwrap_or(PersonId(-1)); @@ -186,7 +189,7 @@ impl<'a> CommentReplyQuery<'a> { .inner_join(person::table.on(comment::creator_id.eq(person::id))) .inner_join(post::table.on(comment::post_id.eq(post::id))) .inner_join(community::table.on(post::community_id.eq(community::id))) - .inner_join(person_alias_1::table) + .inner_join(person_alias_1) .inner_join(comment_aggregates::table.on(comment::id.eq(comment_aggregates::comment_id))) .left_join( community_person_ban::table.on( @@ -234,7 +237,7 @@ impl<'a> CommentReplyQuery<'a> { Person::safe_columns_tuple(), post::all_columns, Community::safe_columns_tuple(), - PersonAlias1::safe_columns_tuple(), + person_alias_1.fields(Person::safe_columns_tuple()), comment_aggregates::all_columns, community_person_ban::all_columns.nullable(), community_follower::all_columns.nullable(), diff --git a/crates/db_views_actor/src/person_block_view.rs b/crates/db_views_actor/src/person_block_view.rs index f287049ade..90d56ccd7b 100644 --- a/crates/db_views_actor/src/person_block_view.rs +++ b/crates/db_views_actor/src/person_block_view.rs @@ -2,21 +2,23 @@ use crate::structs::PersonBlockView; use diesel::{result::Error, *}; use lemmy_db_schema::{ newtypes::PersonId, - schema::{person, person_alias_1, person_block}, - source::person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1}, + schema::{person, person_block}, + source::person::{Person, PersonSafe}, traits::{ToSafe, ViewToVec}, }; -type PersonBlockViewTuple = (PersonSafe, PersonSafeAlias1); +type PersonBlockViewTuple = (PersonSafe, PersonSafe); impl PersonBlockView { pub fn for_person(conn: &mut PgConnection, person_id: PersonId) -> Result, Error> { + let person_alias_1 = diesel::alias!(person as person1); + let res = person_block::table .inner_join(person::table) - .inner_join(person_alias_1::table) // TODO I dont know if this will be smart abt the column + .inner_join(person_alias_1) .select(( Person::safe_columns_tuple(), - PersonAlias1::safe_columns_tuple(), + person_alias_1.fields(Person::safe_columns_tuple()), )) .filter(person_block::person_id.eq(person_id)) .order_by(person_block::published) diff --git a/crates/db_views_actor/src/person_mention_view.rs b/crates/db_views_actor/src/person_mention_view.rs index 8f6c696ec9..e4863db428 100644 --- a/crates/db_views_actor/src/person_mention_view.rs +++ b/crates/db_views_actor/src/person_mention_view.rs @@ -12,7 +12,6 @@ use lemmy_db_schema::{ community_follower, community_person_ban, person, - person_alias_1, person_block, person_mention, post, @@ -20,7 +19,7 @@ use lemmy_db_schema::{ source::{ comment::{Comment, CommentSaved}, community::{Community, CommunityFollower, CommunityPersonBan, CommunitySafe}, - person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1}, + person::{Person, PersonSafe}, person_block::PersonBlock, person_mention::PersonMention, post::Post, @@ -37,7 +36,7 @@ type PersonMentionViewTuple = ( PersonSafe, Post, CommunitySafe, - PersonSafeAlias1, + PersonSafe, CommentAggregates, Option, Option, @@ -52,6 +51,8 @@ impl PersonMentionView { person_mention_id: PersonMentionId, my_person_id: Option, ) -> Result { + let person_alias_1 = diesel::alias!(person as person1); + // The left join below will return None in this case let person_id_join = my_person_id.unwrap_or(PersonId(-1)); @@ -74,7 +75,7 @@ impl PersonMentionView { .inner_join(person::table.on(comment::creator_id.eq(person::id))) .inner_join(post::table.on(comment::post_id.eq(post::id))) .inner_join(community::table.on(post::community_id.eq(community::id))) - .inner_join(person_alias_1::table) + .inner_join(person_alias_1) .inner_join(comment_aggregates::table.on(comment::id.eq(comment_aggregates::comment_id))) .left_join( community_person_ban::table.on( @@ -122,7 +123,7 @@ impl PersonMentionView { Person::safe_columns_tuple(), post::all_columns, Community::safe_columns_tuple(), - PersonAlias1::safe_columns_tuple(), + person_alias_1.fields(Person::safe_columns_tuple()), comment_aggregates::all_columns, community_person_ban::all_columns.nullable(), community_follower::all_columns.nullable(), @@ -181,6 +182,8 @@ impl<'a> PersonMentionQuery<'a> { pub fn list(self) -> Result, Error> { use diesel::dsl::*; + let person_alias_1 = diesel::alias!(person as person1); + // The left join below will return None in this case let person_id_join = self.my_person_id.unwrap_or(PersonId(-1)); @@ -189,7 +192,7 @@ impl<'a> PersonMentionQuery<'a> { .inner_join(person::table.on(comment::creator_id.eq(person::id))) .inner_join(post::table.on(comment::post_id.eq(post::id))) .inner_join(community::table.on(post::community_id.eq(community::id))) - .inner_join(person_alias_1::table) + .inner_join(person_alias_1) .inner_join(comment_aggregates::table.on(comment::id.eq(comment_aggregates::comment_id))) .left_join( community_person_ban::table.on( @@ -237,7 +240,7 @@ impl<'a> PersonMentionQuery<'a> { Person::safe_columns_tuple(), post::all_columns, Community::safe_columns_tuple(), - PersonAlias1::safe_columns_tuple(), + person_alias_1.fields(Person::safe_columns_tuple()), comment_aggregates::all_columns, community_person_ban::all_columns.nullable(), community_follower::all_columns.nullable(), diff --git a/crates/db_views_actor/src/structs.rs b/crates/db_views_actor/src/structs.rs index a5a64436b8..91d40e9627 100644 --- a/crates/db_views_actor/src/structs.rs +++ b/crates/db_views_actor/src/structs.rs @@ -4,7 +4,7 @@ use lemmy_db_schema::{ comment::Comment, comment_reply::CommentReply, community::CommunitySafe, - person::{PersonSafe, PersonSafeAlias1}, + person::PersonSafe, person_mention::PersonMention, post::Post, }, @@ -47,7 +47,7 @@ pub struct CommunityView { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct PersonBlockView { pub person: PersonSafe, - pub target: PersonSafeAlias1, + pub target: PersonSafe, } #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] @@ -57,7 +57,7 @@ pub struct PersonMentionView { pub creator: PersonSafe, pub post: Post, pub community: CommunitySafe, - pub recipient: PersonSafeAlias1, + pub recipient: PersonSafe, pub counts: CommentAggregates, pub creator_banned_from_community: bool, // Left Join to CommunityPersonBan pub subscribed: SubscribedType, // Left join to CommunityFollower @@ -73,7 +73,7 @@ pub struct CommentReplyView { pub creator: PersonSafe, pub post: Post, pub community: CommunitySafe, - pub recipient: PersonSafeAlias1, + pub recipient: PersonSafe, pub counts: CommentAggregates, pub creator_banned_from_community: bool, // Left Join to CommunityPersonBan pub subscribed: SubscribedType, // Left join to CommunityFollower diff --git a/crates/db_views_moderator/src/mod_add_community_view.rs b/crates/db_views_moderator/src/mod_add_community_view.rs index 2889283698..b7b9e93a8f 100644 --- a/crates/db_views_moderator/src/mod_add_community_view.rs +++ b/crates/db_views_moderator/src/mod_add_community_view.rs @@ -2,11 +2,11 @@ use crate::structs::{ModAddCommunityView, ModlogListParams}; use diesel::{result::Error, *}; use lemmy_db_schema::{ newtypes::PersonId, - schema::{community, mod_add_community, person, person_alias_1}, + schema::{community, mod_add_community, person}, source::{ community::{Community, CommunitySafe}, moderator::ModAddCommunity, - person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1}, + person::{Person, PersonSafe}, }, traits::{ToSafe, ViewToVec}, utils::limit_and_offset, @@ -16,11 +16,12 @@ type ModAddCommunityViewTuple = ( ModAddCommunity, Option, CommunitySafe, - PersonSafeAlias1, + PersonSafe, ); impl ModAddCommunityView { pub fn list(conn: &mut PgConnection, params: ModlogListParams) -> Result, Error> { + let person_alias_1 = diesel::alias!(person as person1); let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); let show_mod_names = !params.hide_modlog_names; let show_mod_names_expr = show_mod_names.as_sql::(); @@ -32,13 +33,13 @@ impl ModAddCommunityView { .left_join(person::table.on(admin_names_join)) .inner_join(community::table) .inner_join( - person_alias_1::table.on(mod_add_community::other_person_id.eq(person_alias_1::id)), + person_alias_1.on(mod_add_community::other_person_id.eq(person_alias_1.field(person::id))), ) .select(( mod_add_community::all_columns, Person::safe_columns_tuple().nullable(), Community::safe_columns_tuple(), - PersonAlias1::safe_columns_tuple(), + person_alias_1.fields(Person::safe_columns_tuple()), )) .into_boxed(); @@ -51,7 +52,7 @@ impl ModAddCommunityView { }; if let Some(other_person_id) = params.other_person_id { - query = query.filter(person_alias_1::id.eq(other_person_id)); + query = query.filter(person_alias_1.field(person::id).eq(other_person_id)); }; let (limit, offset) = limit_and_offset(params.page, params.limit)?; diff --git a/crates/db_views_moderator/src/mod_add_view.rs b/crates/db_views_moderator/src/mod_add_view.rs index 12f93999f1..e71552500c 100644 --- a/crates/db_views_moderator/src/mod_add_view.rs +++ b/crates/db_views_moderator/src/mod_add_view.rs @@ -2,19 +2,20 @@ use crate::structs::{ModAddView, ModlogListParams}; use diesel::{result::Error, *}; use lemmy_db_schema::{ newtypes::PersonId, - schema::{mod_add, person, person_alias_1}, + schema::{mod_add, person}, source::{ moderator::ModAdd, - person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1}, + person::{Person, PersonSafe}, }, traits::{ToSafe, ViewToVec}, utils::limit_and_offset, }; -type ModAddViewTuple = (ModAdd, Option, PersonSafeAlias1); +type ModAddViewTuple = (ModAdd, Option, PersonSafe); impl ModAddView { pub fn list(conn: &mut PgConnection, params: ModlogListParams) -> Result, Error> { + let person_alias_1 = diesel::alias!(person as person1); let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); let show_mod_names = !params.hide_modlog_names; let show_mod_names_expr = show_mod_names.as_sql::(); @@ -24,11 +25,11 @@ impl ModAddView { .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join))); let mut query = mod_add::table .left_join(person::table.on(admin_names_join)) - .inner_join(person_alias_1::table.on(mod_add::other_person_id.eq(person_alias_1::id))) + .inner_join(person_alias_1.on(mod_add::other_person_id.eq(person_alias_1.field(person::id)))) .select(( mod_add::all_columns, Person::safe_columns_tuple().nullable(), - PersonAlias1::safe_columns_tuple(), + person_alias_1.fields(Person::safe_columns_tuple()), )) .into_boxed(); @@ -37,7 +38,7 @@ impl ModAddView { }; if let Some(other_person_id) = params.other_person_id { - query = query.filter(person_alias_1::id.eq(other_person_id)); + query = query.filter(person_alias_1.field(person::id).eq(other_person_id)); }; let (limit, offset) = limit_and_offset(params.page, params.limit)?; diff --git a/crates/db_views_moderator/src/mod_ban_from_community_view.rs b/crates/db_views_moderator/src/mod_ban_from_community_view.rs index 30bafd4f1d..bf885dbc16 100644 --- a/crates/db_views_moderator/src/mod_ban_from_community_view.rs +++ b/crates/db_views_moderator/src/mod_ban_from_community_view.rs @@ -2,11 +2,11 @@ use crate::structs::{ModBanFromCommunityView, ModlogListParams}; use diesel::{result::Error, *}; use lemmy_db_schema::{ newtypes::PersonId, - schema::{community, mod_ban_from_community, person, person_alias_1}, + schema::{community, mod_ban_from_community, person}, source::{ community::{Community, CommunitySafe}, moderator::ModBanFromCommunity, - person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1}, + person::{Person, PersonSafe}, }, traits::{ToSafe, ViewToVec}, utils::limit_and_offset, @@ -16,11 +16,12 @@ type ModBanFromCommunityViewTuple = ( ModBanFromCommunity, Option, CommunitySafe, - PersonSafeAlias1, + PersonSafe, ); impl ModBanFromCommunityView { pub fn list(conn: &mut PgConnection, params: ModlogListParams) -> Result, Error> { + let person_alias_1 = diesel::alias!(person as person1); let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); let show_mod_names = !params.hide_modlog_names; let show_mod_names_expr = show_mod_names.as_sql::(); @@ -32,13 +33,14 @@ impl ModBanFromCommunityView { .left_join(person::table.on(admin_names_join)) .inner_join(community::table) .inner_join( - person_alias_1::table.on(mod_ban_from_community::other_person_id.eq(person_alias_1::id)), + person_alias_1 + .on(mod_ban_from_community::other_person_id.eq(person_alias_1.field(person::id))), ) .select(( mod_ban_from_community::all_columns, Person::safe_columns_tuple().nullable(), Community::safe_columns_tuple(), - PersonAlias1::safe_columns_tuple(), + person_alias_1.fields(Person::safe_columns_tuple()), )) .into_boxed(); diff --git a/crates/db_views_moderator/src/mod_ban_view.rs b/crates/db_views_moderator/src/mod_ban_view.rs index b2029b80a0..94bfbc8d58 100644 --- a/crates/db_views_moderator/src/mod_ban_view.rs +++ b/crates/db_views_moderator/src/mod_ban_view.rs @@ -2,19 +2,20 @@ use crate::structs::{ModBanView, ModlogListParams}; use diesel::{result::Error, *}; use lemmy_db_schema::{ newtypes::PersonId, - schema::{mod_ban, person, person_alias_1}, + schema::{mod_ban, person}, source::{ moderator::ModBan, - person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1}, + person::{Person, PersonSafe}, }, traits::{ToSafe, ViewToVec}, utils::limit_and_offset, }; -type ModBanViewTuple = (ModBan, Option, PersonSafeAlias1); +type ModBanViewTuple = (ModBan, Option, PersonSafe); impl ModBanView { pub fn list(conn: &mut PgConnection, params: ModlogListParams) -> Result, Error> { + let person_alias_1 = diesel::alias!(person as person1); let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); let show_mod_names = !params.hide_modlog_names; let show_mod_names_expr = show_mod_names.as_sql::(); @@ -24,11 +25,11 @@ impl ModBanView { .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join))); let mut query = mod_ban::table .left_join(person::table.on(admin_names_join)) - .inner_join(person_alias_1::table.on(mod_ban::other_person_id.eq(person_alias_1::id))) + .inner_join(person_alias_1.on(mod_ban::other_person_id.eq(person_alias_1.field(person::id)))) .select(( mod_ban::all_columns, Person::safe_columns_tuple().nullable(), - PersonAlias1::safe_columns_tuple(), + person_alias_1.fields(Person::safe_columns_tuple()), )) .into_boxed(); @@ -37,7 +38,7 @@ impl ModBanView { }; if let Some(other_person_id) = params.other_person_id { - query = query.filter(person_alias_1::id.eq(other_person_id)); + query = query.filter(person_alias_1.field(person::id).eq(other_person_id)); }; let (limit, offset) = limit_and_offset(params.page, params.limit)?; diff --git a/crates/db_views_moderator/src/mod_lock_post_view.rs b/crates/db_views_moderator/src/mod_lock_post_view.rs index 97aafcc212..6d88c5ae55 100644 --- a/crates/db_views_moderator/src/mod_lock_post_view.rs +++ b/crates/db_views_moderator/src/mod_lock_post_view.rs @@ -2,7 +2,7 @@ use crate::structs::{ModLockPostView, ModlogListParams}; use diesel::{result::Error, *}; use lemmy_db_schema::{ newtypes::PersonId, - schema::{community, mod_lock_post, person, person_alias_1, post}, + schema::{community, mod_lock_post, person, post}, source::{ community::{Community, CommunitySafe}, moderator::ModLockPost, @@ -17,6 +17,7 @@ type ModLockPostViewTuple = (ModLockPost, Option, Post, CommunitySaf impl ModLockPostView { pub fn list(conn: &mut PgConnection, params: ModlogListParams) -> Result, Error> { + let person_alias_1 = diesel::alias!(person as person1); let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); let show_mod_names = !params.hide_modlog_names; let show_mod_names_expr = show_mod_names.as_sql::(); @@ -28,7 +29,7 @@ impl ModLockPostView { .left_join(person::table.on(admin_names_join)) .inner_join(post::table) .inner_join(community::table.on(post::community_id.eq(community::id))) - .inner_join(person_alias_1::table.on(post::creator_id.eq(person_alias_1::id))) + .inner_join(person_alias_1.on(post::creator_id.eq(person_alias_1.field(person::id)))) .select(( mod_lock_post::all_columns, Person::safe_columns_tuple().nullable(), @@ -46,7 +47,7 @@ impl ModLockPostView { }; if let Some(other_person_id) = params.other_person_id { - query = query.filter(person_alias_1::id.eq(other_person_id)); + query = query.filter(person_alias_1.field(person::id).eq(other_person_id)); }; let (limit, offset) = limit_and_offset(params.page, params.limit)?; diff --git a/crates/db_views_moderator/src/mod_remove_comment_view.rs b/crates/db_views_moderator/src/mod_remove_comment_view.rs index 0d40331c54..c0b5884568 100644 --- a/crates/db_views_moderator/src/mod_remove_comment_view.rs +++ b/crates/db_views_moderator/src/mod_remove_comment_view.rs @@ -2,12 +2,12 @@ use crate::structs::{ModRemoveCommentView, ModlogListParams}; use diesel::{result::Error, *}; use lemmy_db_schema::{ newtypes::PersonId, - schema::{comment, community, mod_remove_comment, person, person_alias_1, post}, + schema::{comment, community, mod_remove_comment, person, post}, source::{ comment::Comment, community::{Community, CommunitySafe}, moderator::ModRemoveComment, - person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1}, + person::{Person, PersonSafe}, post::Post, }, traits::{ToSafe, ViewToVec}, @@ -18,13 +18,14 @@ type ModRemoveCommentViewTuple = ( ModRemoveComment, Option, Comment, - PersonSafeAlias1, + PersonSafe, Post, CommunitySafe, ); impl ModRemoveCommentView { pub fn list(conn: &mut PgConnection, params: ModlogListParams) -> Result, Error> { + let person_alias_1 = diesel::alias!(lemmy_db_schema::schema::person as person1); let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); let show_mod_names = !params.hide_modlog_names; let show_mod_names_expr = show_mod_names.as_sql::(); @@ -35,14 +36,14 @@ impl ModRemoveCommentView { let mut query = mod_remove_comment::table .left_join(person::table.on(admin_names_join)) .inner_join(comment::table) - .inner_join(person_alias_1::table.on(comment::creator_id.eq(person_alias_1::id))) + .inner_join(person_alias_1.on(comment::creator_id.eq(person_alias_1.field(person::id)))) .inner_join(post::table.on(comment::post_id.eq(post::id))) .inner_join(community::table.on(post::community_id.eq(community::id))) .select(( mod_remove_comment::all_columns, Person::safe_columns_tuple().nullable(), comment::all_columns, - PersonAlias1::safe_columns_tuple(), + person_alias_1.fields(Person::safe_columns_tuple()), post::all_columns, Community::safe_columns_tuple(), )) @@ -57,7 +58,7 @@ impl ModRemoveCommentView { }; if let Some(other_person_id) = params.other_person_id { - query = query.filter(person_alias_1::id.eq(other_person_id)); + query = query.filter(person_alias_1.field(person::id).eq(other_person_id)); }; let (limit, offset) = limit_and_offset(params.page, params.limit)?; diff --git a/crates/db_views_moderator/src/mod_remove_post_view.rs b/crates/db_views_moderator/src/mod_remove_post_view.rs index df801ecd07..c1bc2e8f5f 100644 --- a/crates/db_views_moderator/src/mod_remove_post_view.rs +++ b/crates/db_views_moderator/src/mod_remove_post_view.rs @@ -2,7 +2,7 @@ use crate::structs::{ModRemovePostView, ModlogListParams}; use diesel::{result::Error, *}; use lemmy_db_schema::{ newtypes::PersonId, - schema::{community, mod_remove_post, person, person_alias_1, post}, + schema::{community, mod_remove_post, person, post}, source::{ community::{Community, CommunitySafe}, moderator::ModRemovePost, @@ -17,6 +17,7 @@ type ModRemovePostViewTuple = (ModRemovePost, Option, Post, Communit impl ModRemovePostView { pub fn list(conn: &mut PgConnection, params: ModlogListParams) -> Result, Error> { + let person_alias_1 = diesel::alias!(person as person1); let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); let show_mod_names = !params.hide_modlog_names; let show_mod_names_expr = show_mod_names.as_sql::(); @@ -28,7 +29,7 @@ impl ModRemovePostView { .left_join(person::table.on(admin_names_join)) .inner_join(post::table) .inner_join(community::table.on(post::community_id.eq(community::id))) - .inner_join(person_alias_1::table.on(post::creator_id.eq(person_alias_1::id))) + .inner_join(person_alias_1.on(post::creator_id.eq(person_alias_1.field(person::id)))) .select(( mod_remove_post::all_columns, Person::safe_columns_tuple().nullable(), @@ -46,7 +47,7 @@ impl ModRemovePostView { }; if let Some(other_person_id) = params.other_person_id { - query = query.filter(person_alias_1::id.eq(other_person_id)); + query = query.filter(person_alias_1.field(person::id).eq(other_person_id)); }; let (limit, offset) = limit_and_offset(params.page, params.limit)?; diff --git a/crates/db_views_moderator/src/mod_sticky_post_view.rs b/crates/db_views_moderator/src/mod_sticky_post_view.rs index 86a27e306c..d802de696e 100644 --- a/crates/db_views_moderator/src/mod_sticky_post_view.rs +++ b/crates/db_views_moderator/src/mod_sticky_post_view.rs @@ -2,7 +2,7 @@ use crate::structs::{ModStickyPostView, ModlogListParams}; use diesel::{result::Error, *}; use lemmy_db_schema::{ newtypes::PersonId, - schema::{community, mod_sticky_post, person, person_alias_1, post}, + schema::{community, mod_sticky_post, person, post}, source::{ community::{Community, CommunitySafe}, moderator::ModStickyPost, @@ -17,6 +17,7 @@ type ModStickyPostViewTuple = (ModStickyPost, Option, Post, Communit impl ModStickyPostView { pub fn list(conn: &mut PgConnection, params: ModlogListParams) -> Result, Error> { + let person_alias_1 = diesel::alias!(person as person1); let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); let show_mod_names = !params.hide_modlog_names; let show_mod_names_expr = show_mod_names.as_sql::(); @@ -27,7 +28,7 @@ impl ModStickyPostView { let mut query = mod_sticky_post::table .left_join(person::table.on(admin_names_join)) .inner_join(post::table) - .inner_join(person_alias_1::table.on(post::creator_id.eq(person_alias_1::id))) + .inner_join(person_alias_1.on(post::creator_id.eq(person_alias_1.field(person::id)))) .inner_join(community::table.on(post::community_id.eq(community::id))) .select(( mod_sticky_post::all_columns, @@ -46,7 +47,7 @@ impl ModStickyPostView { }; if let Some(other_person_id) = params.other_person_id { - query = query.filter(person_alias_1::id.eq(other_person_id)); + query = query.filter(person_alias_1.field(person::id).eq(other_person_id)); }; let (limit, offset) = limit_and_offset(params.page, params.limit)?; diff --git a/crates/db_views_moderator/src/mod_transfer_community_view.rs b/crates/db_views_moderator/src/mod_transfer_community_view.rs index fe541335c8..bea839eb2c 100644 --- a/crates/db_views_moderator/src/mod_transfer_community_view.rs +++ b/crates/db_views_moderator/src/mod_transfer_community_view.rs @@ -2,11 +2,11 @@ use crate::structs::{ModTransferCommunityView, ModlogListParams}; use diesel::{result::Error, *}; use lemmy_db_schema::{ newtypes::PersonId, - schema::{community, mod_transfer_community, person, person_alias_1}, + schema::{community, mod_transfer_community, person}, source::{ community::{Community, CommunitySafe}, moderator::ModTransferCommunity, - person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1}, + person::{Person, PersonSafe}, }, traits::{ToSafe, ViewToVec}, utils::limit_and_offset, @@ -16,11 +16,12 @@ type ModTransferCommunityViewTuple = ( ModTransferCommunity, Option, CommunitySafe, - PersonSafeAlias1, + PersonSafe, ); impl ModTransferCommunityView { pub fn list(conn: &mut PgConnection, params: ModlogListParams) -> Result, Error> { + let person_alias_1 = diesel::alias!(person as person1); let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1)); let show_mod_names = !params.hide_modlog_names; let show_mod_names_expr = show_mod_names.as_sql::(); @@ -32,13 +33,14 @@ impl ModTransferCommunityView { .left_join(person::table.on(admin_names_join)) .inner_join(community::table) .inner_join( - person_alias_1::table.on(mod_transfer_community::other_person_id.eq(person_alias_1::id)), + person_alias_1 + .on(mod_transfer_community::other_person_id.eq(person_alias_1.field(person::id))), ) .select(( mod_transfer_community::all_columns, Person::safe_columns_tuple().nullable(), Community::safe_columns_tuple(), - PersonAlias1::safe_columns_tuple(), + person_alias_1.fields(Person::safe_columns_tuple()), )) .into_boxed(); @@ -51,7 +53,7 @@ impl ModTransferCommunityView { }; if let Some(other_person_id) = params.other_person_id { - query = query.filter(person_alias_1::id.eq(other_person_id)); + query = query.filter(person_alias_1.field(person::id).eq(other_person_id)); }; let (limit, offset) = limit_and_offset(params.page, params.limit)?; diff --git a/crates/db_views_moderator/src/structs.rs b/crates/db_views_moderator/src/structs.rs index 4f6fbbd3ea..863de0704f 100644 --- a/crates/db_views_moderator/src/structs.rs +++ b/crates/db_views_moderator/src/structs.rs @@ -20,7 +20,7 @@ use lemmy_db_schema::{ ModStickyPost, ModTransferCommunity, }, - person::{PersonSafe, PersonSafeAlias1}, + person::PersonSafe, post::Post, }, }; @@ -31,14 +31,14 @@ pub struct ModAddCommunityView { pub mod_add_community: ModAddCommunity, pub moderator: Option, pub community: CommunitySafe, - pub modded_person: PersonSafeAlias1, + pub modded_person: PersonSafe, } #[derive(Debug, Serialize, Deserialize, Clone)] pub struct ModAddView { pub mod_add: ModAdd, pub moderator: Option, - pub modded_person: PersonSafeAlias1, + pub modded_person: PersonSafe, } #[derive(Debug, Serialize, Deserialize, Clone)] @@ -46,14 +46,14 @@ pub struct ModBanFromCommunityView { pub mod_ban_from_community: ModBanFromCommunity, pub moderator: Option, pub community: CommunitySafe, - pub banned_person: PersonSafeAlias1, + pub banned_person: PersonSafe, } #[derive(Debug, Serialize, Deserialize, Clone)] pub struct ModBanView { pub mod_ban: ModBan, pub moderator: Option, - pub banned_person: PersonSafeAlias1, + pub banned_person: PersonSafe, } #[derive(Debug, Serialize, Deserialize, Clone)] @@ -76,7 +76,7 @@ pub struct ModRemoveCommentView { pub mod_remove_comment: ModRemoveComment, pub moderator: Option, pub comment: Comment, - pub commenter: PersonSafeAlias1, + pub commenter: PersonSafe, pub post: Post, pub community: CommunitySafe, } @@ -109,7 +109,7 @@ pub struct ModTransferCommunityView { pub mod_transfer_community: ModTransferCommunity, pub moderator: Option, pub community: CommunitySafe, - pub modded_person: PersonSafeAlias1, + pub modded_person: PersonSafe, } #[derive(Debug, Serialize, Deserialize, Clone)] diff --git a/migrations/2022-09-24-161829_remove_table_aliases/down.sql b/migrations/2022-09-24-161829_remove_table_aliases/down.sql new file mode 100644 index 0000000000..39b439a0aa --- /dev/null +++ b/migrations/2022-09-24-161829_remove_table_aliases/down.sql @@ -0,0 +1,2 @@ +create view person_alias_1 as select * from person; +create view person_alias_2 as select * from person; diff --git a/migrations/2022-09-24-161829_remove_table_aliases/up.sql b/migrations/2022-09-24-161829_remove_table_aliases/up.sql new file mode 100644 index 0000000000..36eabecab7 --- /dev/null +++ b/migrations/2022-09-24-161829_remove_table_aliases/up.sql @@ -0,0 +1,2 @@ +-- Drop the alias views +drop view person_alias_1, person_alias_2;