Fix errors

pull/3755/head
dullbananas 2023-08-02 12:56:59 -07:00 committed by GitHub
parent 4e3829facc
commit c9102c14f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 38 additions and 32 deletions

View File

@ -8,6 +8,7 @@ use diesel::{
JoinOnDsl, JoinOnDsl,
NullableExpressionMethods, NullableExpressionMethods,
QueryDsl, QueryDsl,
Selectable,
SelectableHelper, SelectableHelper,
}; };
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
@ -30,7 +31,7 @@ use lemmy_db_schema::{
comment::CommentWithoutId, comment::CommentWithoutId,
comment_report::CommentReport, comment_report::CommentReport,
community::CommunityWithoutId, community::CommunityWithoutId,
person::PersonWithoutId, person::{Person, PersonWithoutId},
post::PostWithoutId, post::PostWithoutId,
}, },
traits::JoinView, traits::JoinView,
@ -70,12 +71,12 @@ fn queries<'a>() -> Queries<
PostWithoutId::as_select(), PostWithoutId::as_select(),
CommunityWithoutId::as_select(), CommunityWithoutId::as_select(),
PersonWithoutId::as_select(), PersonWithoutId::as_select(),
aliases::person1.fields(PersonWithoutId::as_select()), aliases::person1.fields(<PersonWithoutId as Selectable<Pg>>::construct_selection()),
CommentAggregatesNotInComment::as_select(), CommentAggregatesNotInComment::as_select(),
community_person_ban::id.nullable().is_not_null(), community_person_ban::id.nullable().is_not_null(),
comment_like::score.nullable(), comment_like::score.nullable(),
aliases::person2 aliases::person2
.fields(PersonWithoutId::as_select()) .fields(<PersonWithoutId as Selectable<Pg>>::construct_selection())
.nullable(), .nullable(),
); );
@ -250,6 +251,7 @@ impl JoinView for CommentReportView {
resolver, resolver,
): Self::JoinTuple, ): Self::JoinTuple,
) -> Self { ) -> Self {
let comment = comment.into_full(comment_report.comment_id);
Self { Self {
resolver: resolver resolver: resolver
.zip(comment_report.resolver_id) .zip(comment_report.resolver_id)
@ -261,7 +263,7 @@ impl JoinView for CommentReportView {
creator: creator.into_full(comment_report.creator_id), creator: creator.into_full(comment_report.creator_id),
community: community.into_full(post.community_id), community: community.into_full(post.community_id),
post: post.into_full(comment.post_id), post: post.into_full(comment.post_id),
comment: comment.into_full(comment_report.comment_id), comment,
comment_report, comment_report,
} }
} }

View File

@ -364,10 +364,7 @@ mod tests {
CommentQuery, CommentQuery,
CommentSortType, CommentSortType,
CommentView, CommentView,
Community,
DbPool, DbPool,
Person,
Post,
}, },
structs::LocalUserView, structs::LocalUserView,
}; };
@ -378,13 +375,13 @@ mod tests {
source::{ source::{
actor_language::LocalUserLanguage, actor_language::LocalUserLanguage,
comment::{CommentInsertForm, CommentLike, CommentLikeForm}, comment::{CommentInsertForm, CommentLike, CommentLikeForm},
community::CommunityInsertForm, community::{Community, CommunityInsertForm},
instance::Instance, instance::Instance,
language::Language, language::Language,
local_user::{LocalUser, LocalUserInsertForm}, local_user::{LocalUser, LocalUserInsertForm},
person::PersonInsertForm, person::{Person, PersonInsertForm},
person_block::{PersonBlock, PersonBlockForm}, person_block::{PersonBlock, PersonBlockForm},
post::PostInsertForm, post::{Post, PostInsertForm},
}, },
traits::{Blockable, Crud, Likeable}, traits::{Blockable, Crud, Likeable},
utils::build_db_pool_for_tests, utils::build_db_pool_for_tests,

View File

@ -11,7 +11,7 @@ use std::collections::HashMap;
type CustomEmojiTuple = (CustomEmoji, Option<KeywordTuple>); type CustomEmojiTuple = (CustomEmoji, Option<KeywordTuple>);
type KeywordTuple = (CustomEmojiId, String); type KeywordTuple = (i32, String);
impl CustomEmojiView { impl CustomEmojiView {
pub async fn get(pool: &mut DbPool<'_>, emoji_id: CustomEmojiId) -> Result<Self, Error> { pub async fn get(pool: &mut DbPool<'_>, emoji_id: CustomEmojiId) -> Result<Self, Error> {

View File

@ -115,7 +115,7 @@ impl LocalUserView {
impl JoinView for LocalUserView { impl JoinView for LocalUserView {
type JoinTuple = LocalUserViewTuple; type JoinTuple = LocalUserViewTuple;
fn from_tuple((loal_user, person, counts): Self::JoinTuple) -> Self { fn from_tuple((local_user, person, counts): Self::JoinTuple) -> Self {
Self { Self {
person: person.into_full(local_user.person_id), person: person.into_full(local_user.person_id),
local_user, local_user,

View File

@ -7,6 +7,7 @@ use diesel::{
JoinOnDsl, JoinOnDsl,
NullableExpressionMethods, NullableExpressionMethods,
QueryDsl, QueryDsl,
Selectable,
SelectableHelper, SelectableHelper,
}; };
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
@ -26,7 +27,7 @@ use lemmy_db_schema::{
}, },
source::{ source::{
community::CommunityWithoutId, community::CommunityWithoutId,
person::PersonWithoutId, person::{Person, PersonWithoutId},
post::PostWithoutId, post::PostWithoutId,
post_report::PostReport, post_report::PostReport,
}, },
@ -80,11 +81,11 @@ fn queries<'a>() -> Queries<
PostWithoutId::as_select(), PostWithoutId::as_select(),
CommunityWithoutId::as_select(), CommunityWithoutId::as_select(),
PersonWithoutId::as_select(), PersonWithoutId::as_select(),
aliases::person1.fields(PersonWithoutId::as_select()), aliases::person1.fields(<PersonWithoutId as Selectable<Pg>>::construct_selection()),
community_person_ban::id.nullable().is_not_null(), community_person_ban::id.nullable().is_not_null(),
post_like::score.nullable(), post_like::score.nullable(),
PostAggregatesNotInPost::as_select(), PostAggregatesNotInPost::as_select(),
aliases::person2.fields(PersonWithoutId::as_select.nullable()), aliases::person2.fields(<PersonWithoutId as Selectable<Pg>>::construct_selection().nullable()),
)) ))
}; };
@ -220,9 +221,9 @@ impl JoinView for PostReportView {
resolver, resolver,
): Self::JoinTuple, ): Self::JoinTuple,
) -> Self { ) -> Self {
let post = post.into_full(post_report.post_id);
Self { Self {
resolver: (resolver, post_report.resolver_id) resolver: Option::zip(resolver, post_report.resolver_id)
.zip()
.map(|(resolver, id)| resolver.into_full(id)), .map(|(resolver, id)| resolver.into_full(id)),
counts: counts.into_full(&post), counts: counts.into_full(&post),
my_vote, my_vote,
@ -230,7 +231,7 @@ impl JoinView for PostReportView {
post_creator: post_creator.into_full(post.creator_id), post_creator: post_creator.into_full(post.creator_id),
creator: creator.into_full(post_report.creator_id), creator: creator.into_full(post_report.creator_id),
community: community.into_full(post.community_id), community: community.into_full(post.community_id),
post: post.into_full(post_report.post_id), post,
post_report, post_report,
} }
} }

View File

@ -453,7 +453,6 @@ impl JoinView for PostView {
unread_comments, unread_comments,
): Self::JoinTuple, ): Self::JoinTuple,
) -> Self { ) -> Self {
let counts = a.4.into_full(&a.0);
Self { Self {
creator: creator.into_full(post.creator_id), creator: creator.into_full(post.creator_id),
community: community.into_full(post.community_id), community: community.into_full(post.community_id),

View File

@ -6,6 +6,7 @@ use diesel::{
JoinOnDsl, JoinOnDsl,
NullableExpressionMethods, NullableExpressionMethods,
QueryDsl, QueryDsl,
Selectable,
SelectableHelper, SelectableHelper,
}; };
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
@ -50,9 +51,9 @@ fn queries<'a>() -> Queries<
private_message_report::all_columns, private_message_report::all_columns,
PrivateMessageWithoutId::as_select(), PrivateMessageWithoutId::as_select(),
PersonWithoutId::as_select(), PersonWithoutId::as_select(),
aliases::person1.fields(PersonWithoutId::as_select()), aliases::person1.fields(<PersonWithoutId as Selectable<Pg>>::construct_selection()),
aliases::person2 aliases::person2
.fields(PersonWithoutId::as_select()) .fields(<PersonWithoutId as Selectable<Pg>>::construct_selection())
.nullable(), .nullable(),
)) ))
}; };
@ -134,8 +135,7 @@ impl JoinView for PrivateMessageReportView {
): Self::JoinTuple, ): Self::JoinTuple,
) -> Self { ) -> Self {
Self { Self {
resolver: (resolver, private_message_report.resolver_id) resolver: Option::zip(resolver, private_message_report.resolver_id)
.zip()
.map(|(resolver, id)| resolver.into_full(id)), .map(|(resolver, id)| resolver.into_full(id)),
creator: creator.into_full(private_message_report.creator_id), creator: creator.into_full(private_message_report.creator_id),
private_message_creator: private_message_creator.into_full(private_message.creator_id), private_message_creator: private_message_creator.into_full(private_message.creator_id),

View File

@ -7,6 +7,7 @@ use diesel::{
ExpressionMethods, ExpressionMethods,
JoinOnDsl, JoinOnDsl,
QueryDsl, QueryDsl,
Selectable,
SelectableHelper, SelectableHelper,
}; };
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
@ -37,7 +38,7 @@ fn queries<'a>() -> Queries<
let selection = ( let selection = (
private_message::all_columns, private_message::all_columns,
PersonWithoutId::as_select(), PersonWithoutId::as_select(),
aliases::person1.fields(PersonWithoutId::as_select()), aliases::person1.fields(<PersonWithoutId as Selectable<Pg>>::construct_selection()),
); );
let read = move |mut conn: DbConn<'a>, private_message_id: PrivateMessageId| async move { let read = move |mut conn: DbConn<'a>, private_message_id: PrivateMessageId| async move {

View File

@ -7,6 +7,7 @@ use diesel::{
JoinOnDsl, JoinOnDsl,
NullableExpressionMethods, NullableExpressionMethods,
QueryDsl, QueryDsl,
Selectable,
SelectableHelper, SelectableHelper,
}; };
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
@ -47,7 +48,7 @@ fn queries<'a>() -> Queries<
LocalUserWithoutId::as_select(), LocalUserWithoutId::as_select(),
PersonWithoutId::as_select(), PersonWithoutId::as_select(),
aliases::person1 aliases::person1
.fields(PersonWithoutId::as_select()) .fields(<PersonWithoutId as Selectable<Pg>>::construct_selection())
.nullable(), .nullable(),
)) ))
}; };
@ -148,7 +149,8 @@ impl JoinView for RegistrationApplicationView {
(registration_application, creator_local_user, creator, admin): Self::JoinTuple, (registration_application, creator_local_user, creator, admin): Self::JoinTuple,
) -> Self { ) -> Self {
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: creator.into_full(creator_local_user.person_id),
creator_local_user: creator_local_user.into_full(registration_application.local_user_id), creator_local_user: creator_local_user.into_full(registration_application.local_user_id),
registration_application, registration_application,

View File

@ -1,5 +1,5 @@
use crate::structs::SiteView; use crate::structs::SiteView;
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, QueryDsl}; use diesel::{result::Error, ExpressionMethods, JoinOnDsl, QueryDsl, SelectableHelper};
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use lemmy_db_schema::{ use lemmy_db_schema::{
aggregates::structs::SiteAggregates, aggregates::structs::SiteAggregates,
@ -23,7 +23,7 @@ impl SiteView {
local_site_rate_limit::all_columns, local_site_rate_limit::all_columns,
site_aggregates::all_columns, site_aggregates::all_columns,
)) ))
.first::<(Site, LocalSite, LocalSiteRateLimit, SiteAggregates)>(conn) .first::<(SiteWithoutId, LocalSite, LocalSiteRateLimit, SiteAggregates)>(conn)
.await?; .await?;
site.private_key = None; site.private_key = None;

View File

@ -7,6 +7,7 @@ use diesel::{
JoinOnDsl, JoinOnDsl,
NullableExpressionMethods, NullableExpressionMethods,
QueryDsl, QueryDsl,
Selectable,
SelectableHelper, SelectableHelper,
}; };
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
@ -111,7 +112,7 @@ fn queries<'a>() -> Queries<
PersonWithoutId::as_select(), PersonWithoutId::as_select(),
PostWithoutId::as_select(), PostWithoutId::as_select(),
CommunityWithoutId::as_select(), CommunityWithoutId::as_select(),
aliases::person1.fields(PersonWithoutId::as_select()), aliases::person1.fields(<PersonWithoutId as Selectable<Pg>>::construct_selection()),
CommentAggregatesNotInComment::as_select(), CommentAggregatesNotInComment::as_select(),
community_person_ban::id.nullable().is_not_null(), community_person_ban::id.nullable().is_not_null(),
CommunityFollower::select_subscribed_type(), CommunityFollower::select_subscribed_type(),
@ -234,13 +235,14 @@ impl JoinView for CommentReplyView {
my_vote, my_vote,
): Self::JoinTuple, ): Self::JoinTuple,
) -> Self { ) -> Self {
let comment = comment.into_full(comment.into_full(comment_reply.comment_id));
Self { Self {
counts: counts.into_full(&comment), counts: counts.into_full(&comment),
recipient: recipient.into_full(comment_reply.recipient_id), recipient: recipient.into_full(comment_reply.recipient_id),
community: community.into_full(post.community_id), community: community.into_full(post.community_id),
post: post.into_full(comment.post_id), post: post.into_full(comment.post_id),
creator: creator.into_full(comment.creator_id), creator: creator.into_full(comment.creator_id),
comment: comment.into_full(comment_reply.comment_id), comment,
comment_reply, comment_reply,
creator_banned_from_community, creator_banned_from_community,
subscribed, subscribed,

View File

@ -8,6 +8,7 @@ use diesel::{
JoinOnDsl, JoinOnDsl,
NullableExpressionMethods, NullableExpressionMethods,
QueryDsl, QueryDsl,
Selectable,
SelectableHelper, SelectableHelper,
}; };
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
@ -107,7 +108,7 @@ fn queries<'a>() -> Queries<
PersonWithoutId::as_select(), PersonWithoutId::as_select(),
PostWithoutId::as_select(), PostWithoutId::as_select(),
CommunityWithoutId::as_select(), CommunityWithoutId::as_select(),
aliases::person1.fields(PersonWithoutId::as_select()), aliases::person1.fields(<PersonWithoutId as Selectable<Pg>>::construct_selection()),
CommentAggregatesNotInComment::as_select(), CommentAggregatesNotInComment::as_select(),
community_person_ban::id.nullable().is_not_null(), community_person_ban::id.nullable().is_not_null(),
CommunityFollower::select_subscribed_type(), CommunityFollower::select_subscribed_type(),
@ -251,13 +252,14 @@ impl JoinView for PersonMentionView {
my_vote, my_vote,
): Self::JoinTuple, ): Self::JoinTuple,
) -> Self { ) -> Self {
let comment = comment.into_full(person_mention.comment_id),
Self { Self {
counts: counts.into_full(&comment), counts: counts.into_full(&comment),
recipient: recipient.into_full(person_mention.recipient_id), recipient: recipient.into_full(person_mention.recipient_id),
community: community.into_full(post.community_id), community: community.into_full(post.community_id),
post: post.into_full(comment.post_id), post: post.into_full(comment.post_id),
creator: creator.into_full(comment.creator_id), creator: creator.into_full(comment.creator_id),
comment: comment.into_full(person_mention.comment_id), comment,
person_mention, person_mention,
creator_banned_from_community, creator_banned_from_community,
subscribed, subscribed,