From c9102c14f466a5d6175732625e74183579ee2be5 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Wed, 2 Aug 2023 12:56:59 -0700 Subject: [PATCH] Fix errors --- crates/db_views/src/comment_report_view.rs | 10 ++++++---- crates/db_views/src/comment_view.rs | 9 +++------ crates/db_views/src/custom_emoji_view.rs | 2 +- crates/db_views/src/local_user_view.rs | 2 +- crates/db_views/src/post_report_view.rs | 13 +++++++------ crates/db_views/src/post_view.rs | 1 - crates/db_views/src/private_message_report_view.rs | 8 ++++---- crates/db_views/src/private_message_view.rs | 3 ++- .../db_views/src/registration_application_view.rs | 6 ++++-- crates/db_views/src/site_view.rs | 4 ++-- crates/db_views_actor/src/comment_reply_view.rs | 6 ++++-- crates/db_views_actor/src/person_mention_view.rs | 6 ++++-- 12 files changed, 38 insertions(+), 32 deletions(-) diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index 79e961dd1..48a5e7254 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -8,6 +8,7 @@ use diesel::{ JoinOnDsl, NullableExpressionMethods, QueryDsl, + Selectable, SelectableHelper, }; use diesel_async::RunQueryDsl; @@ -30,7 +31,7 @@ use lemmy_db_schema::{ comment::CommentWithoutId, comment_report::CommentReport, community::CommunityWithoutId, - person::PersonWithoutId, + person::{Person, PersonWithoutId}, post::PostWithoutId, }, traits::JoinView, @@ -70,12 +71,12 @@ fn queries<'a>() -> Queries< PostWithoutId::as_select(), CommunityWithoutId::as_select(), PersonWithoutId::as_select(), - aliases::person1.fields(PersonWithoutId::as_select()), + aliases::person1.fields(>::construct_selection()), CommentAggregatesNotInComment::as_select(), community_person_ban::id.nullable().is_not_null(), comment_like::score.nullable(), aliases::person2 - .fields(PersonWithoutId::as_select()) + .fields(>::construct_selection()) .nullable(), ); @@ -250,6 +251,7 @@ impl JoinView for CommentReportView { resolver, ): Self::JoinTuple, ) -> Self { + let comment = comment.into_full(comment_report.comment_id); Self { resolver: resolver .zip(comment_report.resolver_id) @@ -261,7 +263,7 @@ impl JoinView for CommentReportView { creator: creator.into_full(comment_report.creator_id), community: community.into_full(post.community_id), post: post.into_full(comment.post_id), - comment: comment.into_full(comment_report.comment_id), + comment, comment_report, } } diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index aa2c0112f..459d8876e 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -364,10 +364,7 @@ mod tests { CommentQuery, CommentSortType, CommentView, - Community, DbPool, - Person, - Post, }, structs::LocalUserView, }; @@ -378,13 +375,13 @@ mod tests { source::{ actor_language::LocalUserLanguage, comment::{CommentInsertForm, CommentLike, CommentLikeForm}, - community::CommunityInsertForm, + community::{Community, CommunityInsertForm}, instance::Instance, language::Language, local_user::{LocalUser, LocalUserInsertForm}, - person::PersonInsertForm, + person::{Person, PersonInsertForm}, person_block::{PersonBlock, PersonBlockForm}, - post::PostInsertForm, + post::{Post, PostInsertForm}, }, traits::{Blockable, Crud, Likeable}, utils::build_db_pool_for_tests, diff --git a/crates/db_views/src/custom_emoji_view.rs b/crates/db_views/src/custom_emoji_view.rs index ad59df0ac..a0d1b5847 100644 --- a/crates/db_views/src/custom_emoji_view.rs +++ b/crates/db_views/src/custom_emoji_view.rs @@ -11,7 +11,7 @@ use std::collections::HashMap; type CustomEmojiTuple = (CustomEmoji, Option); -type KeywordTuple = (CustomEmojiId, String); +type KeywordTuple = (i32, String); impl CustomEmojiView { pub async fn get(pool: &mut DbPool<'_>, emoji_id: CustomEmojiId) -> Result { diff --git a/crates/db_views/src/local_user_view.rs b/crates/db_views/src/local_user_view.rs index f1150a94f..03414f2e6 100644 --- a/crates/db_views/src/local_user_view.rs +++ b/crates/db_views/src/local_user_view.rs @@ -115,7 +115,7 @@ impl LocalUserView { impl JoinView for LocalUserView { type JoinTuple = LocalUserViewTuple; - fn from_tuple((loal_user, person, counts): Self::JoinTuple) -> Self { + fn from_tuple((local_user, person, counts): Self::JoinTuple) -> Self { Self { person: person.into_full(local_user.person_id), local_user, diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index e3908bc11..11b4952b2 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -7,6 +7,7 @@ use diesel::{ JoinOnDsl, NullableExpressionMethods, QueryDsl, + Selectable, SelectableHelper, }; use diesel_async::RunQueryDsl; @@ -26,7 +27,7 @@ use lemmy_db_schema::{ }, source::{ community::CommunityWithoutId, - person::PersonWithoutId, + person::{Person, PersonWithoutId}, post::PostWithoutId, post_report::PostReport, }, @@ -80,11 +81,11 @@ fn queries<'a>() -> Queries< PostWithoutId::as_select(), CommunityWithoutId::as_select(), PersonWithoutId::as_select(), - aliases::person1.fields(PersonWithoutId::as_select()), + aliases::person1.fields(>::construct_selection()), community_person_ban::id.nullable().is_not_null(), post_like::score.nullable(), PostAggregatesNotInPost::as_select(), - aliases::person2.fields(PersonWithoutId::as_select.nullable()), + aliases::person2.fields(>::construct_selection().nullable()), )) }; @@ -220,9 +221,9 @@ impl JoinView for PostReportView { resolver, ): Self::JoinTuple, ) -> Self { + let post = post.into_full(post_report.post_id); Self { - resolver: (resolver, post_report.resolver_id) - .zip() + resolver: Option::zip(resolver, post_report.resolver_id) .map(|(resolver, id)| resolver.into_full(id)), counts: counts.into_full(&post), my_vote, @@ -230,7 +231,7 @@ impl JoinView for PostReportView { post_creator: post_creator.into_full(post.creator_id), creator: creator.into_full(post_report.creator_id), community: community.into_full(post.community_id), - post: post.into_full(post_report.post_id), + post, post_report, } } diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 8a310e8a7..5f568dbe8 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -453,7 +453,6 @@ impl JoinView for PostView { unread_comments, ): Self::JoinTuple, ) -> Self { - let counts = a.4.into_full(&a.0); Self { creator: creator.into_full(post.creator_id), community: community.into_full(post.community_id), diff --git a/crates/db_views/src/private_message_report_view.rs b/crates/db_views/src/private_message_report_view.rs index f03ce6c2a..5e7e61687 100644 --- a/crates/db_views/src/private_message_report_view.rs +++ b/crates/db_views/src/private_message_report_view.rs @@ -6,6 +6,7 @@ use diesel::{ JoinOnDsl, NullableExpressionMethods, QueryDsl, + Selectable, SelectableHelper, }; use diesel_async::RunQueryDsl; @@ -50,9 +51,9 @@ fn queries<'a>() -> Queries< private_message_report::all_columns, PrivateMessageWithoutId::as_select(), PersonWithoutId::as_select(), - aliases::person1.fields(PersonWithoutId::as_select()), + aliases::person1.fields(>::construct_selection()), aliases::person2 - .fields(PersonWithoutId::as_select()) + .fields(>::construct_selection()) .nullable(), )) }; @@ -134,8 +135,7 @@ impl JoinView for PrivateMessageReportView { ): Self::JoinTuple, ) -> Self { Self { - resolver: (resolver, private_message_report.resolver_id) - .zip() + resolver: Option::zip(resolver, private_message_report.resolver_id) .map(|(resolver, id)| resolver.into_full(id)), creator: creator.into_full(private_message_report.creator_id), private_message_creator: private_message_creator.into_full(private_message.creator_id), diff --git a/crates/db_views/src/private_message_view.rs b/crates/db_views/src/private_message_view.rs index e44c49e9d..d7d2925b3 100644 --- a/crates/db_views/src/private_message_view.rs +++ b/crates/db_views/src/private_message_view.rs @@ -7,6 +7,7 @@ use diesel::{ ExpressionMethods, JoinOnDsl, QueryDsl, + Selectable, SelectableHelper, }; use diesel_async::RunQueryDsl; @@ -37,7 +38,7 @@ fn queries<'a>() -> Queries< let selection = ( private_message::all_columns, PersonWithoutId::as_select(), - aliases::person1.fields(PersonWithoutId::as_select()), + aliases::person1.fields(>::construct_selection()), ); let read = move |mut conn: DbConn<'a>, private_message_id: PrivateMessageId| async move { diff --git a/crates/db_views/src/registration_application_view.rs b/crates/db_views/src/registration_application_view.rs index ab22bbd3d..13f82b04c 100644 --- a/crates/db_views/src/registration_application_view.rs +++ b/crates/db_views/src/registration_application_view.rs @@ -7,6 +7,7 @@ use diesel::{ JoinOnDsl, NullableExpressionMethods, QueryDsl, + Selectable, SelectableHelper, }; use diesel_async::RunQueryDsl; @@ -47,7 +48,7 @@ fn queries<'a>() -> Queries< LocalUserWithoutId::as_select(), PersonWithoutId::as_select(), aliases::person1 - .fields(PersonWithoutId::as_select()) + .fields(>::construct_selection()) .nullable(), )) }; @@ -148,7 +149,8 @@ impl JoinView for RegistrationApplicationView { (registration_application, creator_local_user, creator, admin): Self::JoinTuple, ) -> Self { Self { - admin: admin.into_full(registration_application.admin_id), + admin: Option::zip(admin, registration_application.admin_id) + .map(|admin, id| admin.into_full(id)), creator: creator.into_full(creator_local_user.person_id), creator_local_user: creator_local_user.into_full(registration_application.local_user_id), registration_application, diff --git a/crates/db_views/src/site_view.rs b/crates/db_views/src/site_view.rs index 27495a7a9..3e5e08387 100644 --- a/crates/db_views/src/site_view.rs +++ b/crates/db_views/src/site_view.rs @@ -1,5 +1,5 @@ use crate::structs::SiteView; -use diesel::{result::Error, ExpressionMethods, JoinOnDsl, QueryDsl}; +use diesel::{result::Error, ExpressionMethods, JoinOnDsl, QueryDsl, SelectableHelper}; use diesel_async::RunQueryDsl; use lemmy_db_schema::{ aggregates::structs::SiteAggregates, @@ -23,7 +23,7 @@ impl SiteView { local_site_rate_limit::all_columns, site_aggregates::all_columns, )) - .first::<(Site, LocalSite, LocalSiteRateLimit, SiteAggregates)>(conn) + .first::<(SiteWithoutId, LocalSite, LocalSiteRateLimit, SiteAggregates)>(conn) .await?; site.private_key = None; diff --git a/crates/db_views_actor/src/comment_reply_view.rs b/crates/db_views_actor/src/comment_reply_view.rs index 965acb237..55a585997 100644 --- a/crates/db_views_actor/src/comment_reply_view.rs +++ b/crates/db_views_actor/src/comment_reply_view.rs @@ -7,6 +7,7 @@ use diesel::{ JoinOnDsl, NullableExpressionMethods, QueryDsl, + Selectable, SelectableHelper, }; use diesel_async::RunQueryDsl; @@ -111,7 +112,7 @@ fn queries<'a>() -> Queries< PersonWithoutId::as_select(), PostWithoutId::as_select(), CommunityWithoutId::as_select(), - aliases::person1.fields(PersonWithoutId::as_select()), + aliases::person1.fields(>::construct_selection()), CommentAggregatesNotInComment::as_select(), community_person_ban::id.nullable().is_not_null(), CommunityFollower::select_subscribed_type(), @@ -234,13 +235,14 @@ impl JoinView for CommentReplyView { my_vote, ): Self::JoinTuple, ) -> Self { + let comment = comment.into_full(comment.into_full(comment_reply.comment_id)); Self { counts: counts.into_full(&comment), recipient: recipient.into_full(comment_reply.recipient_id), community: community.into_full(post.community_id), post: post.into_full(comment.post_id), creator: creator.into_full(comment.creator_id), - comment: comment.into_full(comment_reply.comment_id), + comment, comment_reply, creator_banned_from_community, subscribed, diff --git a/crates/db_views_actor/src/person_mention_view.rs b/crates/db_views_actor/src/person_mention_view.rs index ea5e7599b..ae1ed83ed 100644 --- a/crates/db_views_actor/src/person_mention_view.rs +++ b/crates/db_views_actor/src/person_mention_view.rs @@ -8,6 +8,7 @@ use diesel::{ JoinOnDsl, NullableExpressionMethods, QueryDsl, + Selectable, SelectableHelper, }; use diesel_async::RunQueryDsl; @@ -107,7 +108,7 @@ fn queries<'a>() -> Queries< PersonWithoutId::as_select(), PostWithoutId::as_select(), CommunityWithoutId::as_select(), - aliases::person1.fields(PersonWithoutId::as_select()), + aliases::person1.fields(>::construct_selection()), CommentAggregatesNotInComment::as_select(), community_person_ban::id.nullable().is_not_null(), CommunityFollower::select_subscribed_type(), @@ -251,13 +252,14 @@ impl JoinView for PersonMentionView { my_vote, ): Self::JoinTuple, ) -> Self { + let comment = comment.into_full(person_mention.comment_id), Self { counts: counts.into_full(&comment), recipient: recipient.into_full(person_mention.recipient_id), community: community.into_full(post.community_id), post: post.into_full(comment.post_id), creator: creator.into_full(comment.creator_id), - comment: comment.into_full(person_mention.comment_id), + comment, person_mention, creator_banned_from_community, subscribed,