WithoutId

pull/3755/head
dullbananas 2023-07-31 19:55:16 -07:00 committed by GitHub
parent 86a433b0b3
commit 5e86922b0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 381 additions and 195 deletions

View File

@ -128,6 +128,7 @@ rustls = { version = "0.21.3", features = ["dangerous_configuration"] }
futures-util = "0.3.28"
tokio-postgres = "0.7.8"
tokio-postgres-rustls = "0.10.0"
macro_rules_attribute = "0.2.0
[dependencies]
lemmy_api = { workspace = true }

View File

@ -34,6 +34,8 @@ full = [
"tokio-postgres",
"tokio-postgres-rustls",
"rustls",
"macro_rules_attribute",
"paste",
]
[dependencies]
@ -75,6 +77,8 @@ tokio-postgres = { workspace = true, optional = true }
tokio-postgres-rustls = { workspace = true, optional = true }
rustls = { workspace = true, optional = true }
uuid = { workspace = true, features = ["v4"] }
macro_rules_attribute = { workspace = true, optional = true }
paste = { workspace = true, optional = true }
[dev-dependencies]
serial_test = { workspace = true }

View File

@ -20,6 +20,17 @@ extern crate diesel_migrations;
#[macro_use]
extern crate async_trait;
#[cfg(feature = "full")]
#[macro_use]
extern crate macro_rules_attribute;
#[cfg(feature = "full")]
#[macro_use]
extern crate paste;
#[cfg(feature = "full)]
#[macro_use]
mod without_id;
pub mod aggregates;
#[cfg(feature = "full")]
pub mod impls;

View File

@ -0,0 +1,63 @@
/// `macro_rules_attribute::derive(WithoutId!)` generates a variant of the struct with
/// `WithoutId` added to the name and no `id` field.
///
/// This is useful for making less redundant selections of multiple joined tables.
/// For example, selecting both `comment::post_id` and `post::id` is redundant if they
/// have the same value. In this case, the selection of `post::id` can be avoided by selecting
/// `PostWithoutId::as_select()` instead of `post::all_columns`.
///
/// This macro generates an `into_full` method, which converts to the sturct with `id`.
/// For example, `PostWithoutId` would have this:
///
/// `pub fn into_full(self, id: PostId) -> Post`
///
/// The `id` value can come from a column in another table, like `comment::post_id`.
///
/// The generated struct implements `Selectable` and `Queryable`.
macro_rules! WithoutId {
(
#[diesel(table_name = $table_name:ident)]
$(#[$_struct_meta:meta])*
$vis:vis struct $struct_name:ident {
$(#[$_id_meta:meta])*
$_id_vis:vis id: $id_type:ty,
$(
$(#[$_field_meta:meta])*
$field_vis:vis $field_name:ident : $field_type:ty,
)*
}
) => {
::paste::paste! {
#[derive(::diesel::Queryable, ::diesel::Selectable)]
#[diesel(table_name = $table_name)]
$vis struct [<$struct_name WithoutId>] {
$(
// Field attributes are not kept because either they are for other
// derive macros, or they are `#[cfg(...)]` which is evaluated before
// macro expansion.
$field_vis $field_name : $field_type,
)*
}
impl [<$struct_name WithoutId>] {
pub fn into_full(self, id: $id_type) -> $struct_name {
$struct_name {
$($field_name : self.$field_name,)*
id,
}
}
}
}
};
// Keep on removing the first attribute until `diesel(table_name = ...)` becomes
// the first, which will cause the first pattern to be matched.
(#[$_meta:meta] $($remaining:tt)*) => {
$($remaining)*
};
// This pattern is matched when there's no attributes.
($_vis:vis struct $($_tt:tt)*) => {
::std::compile_error!("`#[diesel(table_name = ...)]` is missing");
};
}

View File

@ -27,11 +27,11 @@ use lemmy_db_schema::{
post,
},
source::{
comment::Comment,
comment::CommentWithoutId,
comment_report::CommentReport,
community::Community,
person::Person,
post::Post,
community::CommunityWithoutId,
person::PersonWithoutId,
post::PostWithoutId,
},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
@ -66,15 +66,15 @@ fn queries<'a>() -> Queries<
let selection = (
comment_report::all_columns,
comment::all_columns,
post::all_columns,
community::all_columns,
person::all_columns,
aliases::person1.fields(person::all_columns),
CommentWithoutId::as_select(),
PostWithoutId::as_select(),
CommunityWithoutId::as_select(),
PersonWithoutId::as_select(),
aliases::person1.fields(PersonWithoutId::as_select()),
CommentAggregatesNotInComment::as_select(),
community_person_ban::id.nullable().is_not_null(),
comment_like::score.nullable(),
aliases::person2.fields(person::all_columns).nullable(),
aliases::person2.fields(PersonWithoutId::as_select()).nullable(),
);
let read = move |mut conn: DbConn<'a>, (report_id, my_person_id): (CommentReportId, PersonId)| async move {
@ -223,30 +223,42 @@ impl CommentReportQuery {
impl JoinView for CommentReportView {
type JoinTuple = (
CommentReport,
Comment,
Post,
Community,
Person,
Person,
CommentWithoutId,
PostWithoutId,
CommunityWithoutId,
PersonWithoutId,
PersonWithoutId,
CommentAggregatesNotInComment,
bool,
Option<i16>,
Option<Person>,
Option<PersonWithoutId>,
);
fn from_tuple(a: Self::JoinTuple) -> Self {
let counts = a.6.into_full(&a.1);
Self {
comment_report: a.0,
comment: a.1,
post: a.2,
community: a.3,
creator: a.4,
comment_creator: a.5,
fn from_tuple(
(
comment_report,
comment,
post,
community,
creator,
comment_creator,
counts,
creator_banned_from_community: a.7,
my_vote: a.8,
resolver: a.9,
creator_banned_from_community,
my_vote,
resolver,
): Self::JoinTuple,
) -> Self {
Self {
resolver: resolver.zip(comment_report.resolver_id).map(|(resolver, id)| resolver.into_full(id)),
my_vote,
creator_banned_from_community,
counts: counts.into_full(&comment),
comment_creator: comment_creator.into_full(comment.creator_id),
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_report,
}
}
}

View File

@ -31,9 +31,9 @@ use lemmy_db_schema::{
},
source::{
comment::Comment,
community::{Community, CommunityFollower},
person::Person,
post::Post,
community::{CommunityWithoutId, CommunityFollower},
person::PersonWithoutId,
post::PostWithoutId,
},
traits::JoinView,
utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
@ -44,9 +44,9 @@ use lemmy_db_schema::{
type CommentViewTuple = (
Comment,
Person,
Post,
Community,
PersonWithoutId,
PostWithoutId,
CommunityWithoutId,
CommentAggregatesNotInComment,
bool,
SubscribedType,
@ -106,9 +106,9 @@ fn queries<'a>() -> Queries<
let selection = (
comment::all_columns,
person::all_columns,
post::all_columns,
community::all_columns,
PersonWithoutId::as_select(),
PostWithoutId::as_select(),
CommunityWithoutId::as_select(),
CommentAggregatesNotInComment::as_select(),
community_person_ban::id.nullable().is_not_null(),
CommunityFollower::select_subscribed_type(),
@ -324,19 +324,31 @@ impl<'a> CommentQuery<'a> {
impl JoinView for CommentView {
type JoinTuple = CommentViewTuple;
fn from_tuple(a: Self::JoinTuple) -> Self {
let counts = a.4.into_full(&a.0);
Self {
comment: a.0,
creator: a.1,
post: a.2,
community: a.3,
fn from_tuple(
(
comment,
creator,
post,
community,
counts,
creator_banned_from_community: a.5,
subscribed: a.6,
saved: a.7,
creator_blocked: a.8,
my_vote: a.9,
creator_banned_from_community,
subscribed,
saved,
creator_blocked,
my_vote,
): Self::JoinTuple,
) -> Self {
Self {
counts: counts.into_full(&comment),
community: community.into_full(post.community_id),
post: post.into_full(comment.post_id),
creator: creator.into_full(comment.creator_id),
comment,
creator_banned_from_community,
subscribed,
saved,
creator_blocked,
my_vote,
}
}
}

View File

@ -9,7 +9,9 @@ use lemmy_db_schema::{
};
use std::collections::HashMap;
type CustomEmojiTuple = (CustomEmoji, Option<CustomEmojiKeyword>);
type CustomEmojiTuple = (CustomEmoji, Option<KeywordTuple>);
type KeywordTuple = (CustomEmojiId, String);
impl CustomEmojiView {
pub async fn get(pool: &mut DbPool<'_>, emoji_id: CustomEmojiId) -> Result<Self, Error> {
@ -21,7 +23,7 @@ impl CustomEmojiView {
)
.select((
custom_emoji::all_columns,
custom_emoji_keyword::all_columns.nullable(), // (or all the columns if you want)
(custom_emoji_keyword::id, custom_emoji_keyword::keyword).nullable(), // (or all the columns if you want)
))
.load::<CustomEmojiTuple>(conn)
.await?;
@ -49,7 +51,7 @@ impl CustomEmojiView {
.then_order_by(custom_emoji::id)
.select((
custom_emoji::all_columns,
custom_emoji_keyword::all_columns.nullable(), // (or all the columns if you want)
(custom_emoji_keyword::id, custom_emoji_keyword::keyword).nullable(), // (or all the columns if you want)
))
.load::<CustomEmojiTuple>(conn)
.await?;
@ -71,7 +73,11 @@ impl CustomEmojiView {
}
if let Some(item_keyword) = &item.1 {
if let Some(keywords) = hash.get_mut(&emoji_id) {
keywords.push(item_keyword.clone())
keywords.push(CustomEmojiKeyword {
id: item_keyword.0,
custom_emoji_id: emoji_id,
keyword: item_keyword.1.clone(),
})
}
}
}

View File

@ -1,16 +1,16 @@
use crate::structs::LocalUserView;
use diesel::{result::Error, BoolExpressionMethods, ExpressionMethods, JoinOnDsl, QueryDsl};
use diesel::{result::Error, BoolExpressionMethods, ExpressionMethods, JoinOnDsl, QueryDsl, SelectableHelper};
use diesel_async::RunQueryDsl;
use lemmy_db_schema::{
aggregates::structs::PersonAggregates,
newtypes::{LocalUserId, PersonId},
schema::{local_user, person, person_aggregates},
source::{local_user::LocalUser, person::Person},
source::{local_user::LocalUser, person::PersonWithoutId},
traits::JoinView,
utils::{functions::lower, DbConn, DbPool, ListFn, Queries, ReadFn},
};
type LocalUserViewTuple = (LocalUser, Person, PersonAggregates);
type LocalUserViewTuple = (LocalUser, PersonWithoutId, PersonAggregates);
enum ReadBy<'a> {
Id(LocalUserId),
@ -28,7 +28,7 @@ fn queries<'a>(
) -> Queries<impl ReadFn<'a, LocalUserView, ReadBy<'a>>, impl ListFn<'a, LocalUserView, ListMode>> {
let selection = (
local_user::all_columns,
person::all_columns,
PersonWithoutId::as_select(,
person_aggregates::all_columns,
);
@ -108,11 +108,11 @@ impl LocalUserView {
impl JoinView for LocalUserView {
type JoinTuple = LocalUserViewTuple;
fn from_tuple(a: Self::JoinTuple) -> Self {
fn from_tuple((loal_user, person, counts): Self::JoinTuple) -> Self {
Self {
local_user: a.0,
person: a.1,
counts: a.2,
person: person.into_full(local_user.person_id),
local_user,
counts,
}
}
}

View File

@ -24,21 +24,21 @@ use lemmy_db_schema::{
post_like,
post_report,
},
source::{community::Community, person::Person, post::Post, post_report::PostReport},
source::{community::CommunityWithoutId, person::PersonWithoutId, post::PostWithoutId, post_report::PostReport},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
};
type PostReportViewTuple = (
PostReport,
Post,
Community,
Person,
Person,
PostWithoutId,
CommunityWithoutId,
PersonWithoutId,
PersonWithoutId,
bool,
Option<i16>,
PostAggregatesNotInPost,
Option<Person>,
Option<PersonWithoutId>,
);
fn queries<'a>() -> Queries<
@ -72,14 +72,14 @@ fn queries<'a>() -> Queries<
)
.select((
post_report::all_columns,
post::all_columns,
community::all_columns,
person::all_columns,
aliases::person1.fields(person::all_columns),
PostWithoutId::as_select(),
CommunityWithoutId::as_select(),
PersonWithoutId::as_select(),
aliases::person1.fields(PersonWithoutId::as_select()),
community_person_ban::id.nullable().is_not_null(),
post_like::score.nullable(),
PostAggregatesNotInPost::as_select(),
aliases::person2.fields(person::all_columns.nullable()),
aliases::person2.fields(PersonWithoutId::as_select.nullable()),
))
};
@ -202,18 +202,29 @@ impl PostReportQuery {
impl JoinView for PostReportView {
type JoinTuple = PostReportViewTuple;
fn from_tuple(a: Self::JoinTuple) -> Self {
let counts = a.7.into_full(&a.1);
Self {
post_report: a.0,
post: a.1,
community: a.2,
creator: a.3,
post_creator: a.4,
creator_banned_from_community: a.5,
my_vote: a.6,
fn from_tuple(
(
post_report,
post,
community,
creator,
post_creator,
creator_banned_from_community,
my_vote,
counts,
resolver: a.8,
resolver,
): Self::JoinTuple,
) -> Self {
Self {
resolver: (resolver, post_report.resolver_id).zip().map(|(resolver, id)| resolver.into_full(id)),
counts: counts.into_full(&post),
my_vote,
creator_banned_from_community,
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_report,
}
}
}

View File

@ -35,8 +35,8 @@ use lemmy_db_schema::{
post_saved,
},
source::{
community::{Community, CommunityFollower},
person::Person,
community::{CommunityWithoutId, CommunityFollower},
person::PersonWithoutId,
post::Post,
},
traits::JoinView,
@ -49,8 +49,8 @@ use tracing::debug;
type PostViewTuple = (
Post,
Person,
Community,
PersonWithoutId,
CommunityWithoutId,
bool,
PostAggregatesNotInPost,
SubscribedType,
@ -135,8 +135,8 @@ fn queries<'a>() -> Queries<
let selection = (
post::all_columns,
person::all_columns,
community::all_columns,
PersonWithoutId::as_select(),
CommunityWithoutId::as_select(),
community_person_ban::id.nullable().is_not_null(),
PostAggregatesNotInPost::as_select(),
CommunityFollower::select_subscribed_type(),
@ -438,20 +438,34 @@ impl<'a> PostQuery<'a> {
impl JoinView for PostView {
type JoinTuple = PostViewTuple;
fn from_tuple(a: Self::JoinTuple) -> Self {
fn from_tuple(
(
post,
creator,
community,
creator_banned_from_community,
counts,
subscribed,
saved,
read,
creator_blocked,
my_vote,
unread_comments,
): Self::JoinTuple,
) -> Self {
let counts = a.4.into_full(&a.0);
Self {
post: a.0,
creator: a.1,
community: a.2,
creator_banned_from_community: a.3,
counts,
subscribed: a.5,
saved: a.6,
read: a.7,
creator_blocked: a.8,
my_vote: a.9,
unread_comments: a.10,
creator: creator.into_full(post.creator_id),
community: community.into_full(post.community_id),
counts: counts.into_full(&post),
post,
creator_banned_from_community,
subscribed,
saved,
read,
creator_blocked,
my_vote,
unread_comments,
}
}
}

View File

@ -6,6 +6,7 @@ use diesel::{
JoinOnDsl,
NullableExpressionMethods,
QueryDsl,
SelectableHelper,
};
use diesel_async::RunQueryDsl;
use lemmy_db_schema::{
@ -13,8 +14,8 @@ use lemmy_db_schema::{
newtypes::PrivateMessageReportId,
schema::{person, private_message, private_message_report},
source::{
person::Person,
private_message::PrivateMessage,
person::PersonWithoutId,
private_message::PrivateMessageWithoutId,
private_message_report::PrivateMessageReport,
},
traits::JoinView,
@ -23,10 +24,10 @@ use lemmy_db_schema::{
type PrivateMessageReportViewTuple = (
PrivateMessageReport,
PrivateMessage,
Person,
Person,
Option<Person>,
PrivateMessageWithoutId,
PersonWithoutId,
PersonWithoutId,
Option<PersonWithoutId>,
);
fn queries<'a>() -> Queries<
@ -47,10 +48,10 @@ fn queries<'a>() -> Queries<
))
.select((
private_message_report::all_columns,
private_message::all_columns,
person::all_columns,
aliases::person1.fields(person::all_columns),
aliases::person2.fields(person::all_columns).nullable(),
PrivateMessageWithoutId::as_select(),
PersonWithoutId::as_select(),
aliases::person1.fields(PersonWithoutId::as_select()),
aliases::person2.fields(PersonWithoutId::as_select()).nullable(),
))
};
@ -121,13 +122,21 @@ impl PrivateMessageReportQuery {
impl JoinView for PrivateMessageReportView {
type JoinTuple = PrivateMessageReportViewTuple;
fn from_tuple(a: Self::JoinTuple) -> Self {
fn from_tuple(
(
private_message_report,
private_message,
private_message_creator,
creator,
resolver,
): Self::JoinTuple,
) -> Self {
Self {
private_message_report: a.0,
private_message: a.1,
private_message_creator: a.2,
creator: a.3,
resolver: a.4,
resolver: (resolver, private_message_report.resolver_id).zip().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),
private_message: private_message.into_full(private_message_report.private_message_id),
private_message_report,
}
}
}

View File

@ -7,19 +7,20 @@ use diesel::{
ExpressionMethods,
JoinOnDsl,
QueryDsl,
SelectableHelper,
};
use diesel_async::RunQueryDsl;
use lemmy_db_schema::{
aliases,
newtypes::{PersonId, PrivateMessageId},
schema::{person, private_message},
source::{person::Person, private_message::PrivateMessage},
source::{person::PersonWithoutId, private_message::PrivateMessage},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
};
use tracing::debug;
type PrivateMessageViewTuple = (PrivateMessage, Person, Person);
type PrivateMessageViewTuple = (PrivateMessage, PersonWithoutId, PersonWithoutId);
fn queries<'a>() -> Queries<
impl ReadFn<'a, PrivateMessageView, PrivateMessageId>,
@ -35,8 +36,8 @@ fn queries<'a>() -> Queries<
let selection = (
private_message::all_columns,
person::all_columns,
aliases::person1.fields(person::all_columns),
PersonWithoutId::as_select(),
aliases::person1.fields(PersonWithoutId::as_select()),
);
let read = move |mut conn: DbConn<'a>, private_message_id: PrivateMessageId| async move {
@ -129,11 +130,17 @@ impl PrivateMessageQuery {
impl JoinView for PrivateMessageView {
type JoinTuple = PrivateMessageViewTuple;
fn from_tuple(a: Self::JoinTuple) -> Self {
fn from_tuple(
(
private_message,
creator,
recipient,
): Self::JoinTuple,
) -> Self {
Self {
private_message: a.0,
creator: a.1,
recipient: a.2,
creator: creator.into_full(private_message.creator_id),
recipient: recipient.into_full(private_message.recipient_id),
private_message,
}
}
}

View File

@ -7,14 +7,15 @@ use diesel::{
JoinOnDsl,
NullableExpressionMethods,
QueryDsl,
SelectableHelper,
};
use diesel_async::RunQueryDsl;
use lemmy_db_schema::{
aliases,
schema::{local_user, person, registration_application},
source::{
local_user::LocalUser,
person::Person,
local_user::LocalUserWithoutId,
person::PersonWithoutId,
registration_application::RegistrationApplication,
},
traits::JoinView,
@ -22,7 +23,7 @@ use lemmy_db_schema::{
};
type RegistrationApplicationViewTuple =
(RegistrationApplication, LocalUser, Person, Option<Person>);
(RegistrationApplication, LocalUserWithoutId, PersonWithoutId, Option<PersonWithoutId>);
fn queries<'a>() -> Queries<
impl ReadFn<'a, RegistrationApplicationView, i32>,
@ -39,9 +40,9 @@ fn queries<'a>() -> Queries<
.order_by(registration_application::published.desc())
.select((
registration_application::all_columns,
local_user::all_columns,
person::all_columns,
aliases::person1.fields(person::all_columns).nullable(),
LocalUserWithoutId::as_select(),
PersonWithoutId::as_select(),
aliases::person1.fields(PersonWithoutId::as_select()).nullable(),
))
};
@ -137,12 +138,19 @@ impl RegistrationApplicationQuery {
impl JoinView for RegistrationApplicationView {
type JoinTuple = RegistrationApplicationViewTuple;
fn from_tuple(a: Self::JoinTuple) -> Self {
fn from_tuple(
(
registration_application,
creator_local_user,
creator,
admin,
): Self::JoinTuple,
) -> Self {
Self {
registration_application: a.0,
creator_local_user: a.1,
creator: a.2,
admin: a.3,
admin: admin.into_full(registration_application.admin_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,
}
}
}

View File

@ -4,7 +4,7 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{
aggregates::structs::SiteAggregates,
schema::{local_site, local_site_rate_limit, site, site_aggregates},
source::{local_site::LocalSite, local_site_rate_limit::LocalSiteRateLimit, site::Site},
source::{local_site::LocalSite, local_site_rate_limit::LocalSiteRateLimit, site::SiteWithoutId},
utils::{get_conn, DbPool},
};
@ -18,7 +18,7 @@ impl SiteView {
)
.inner_join(site_aggregates::table)
.select((
site::all_columns,
SiteWithoutId::as_select(),
local_site::all_columns,
local_site_rate_limit::all_columns,
site_aggregates::all_columns,
@ -28,7 +28,7 @@ impl SiteView {
site.private_key = None;
Ok(SiteView {
site,
site: site.into_full(local_site.site_id),
local_site,
local_site_rate_limit,
counts,

View File

@ -28,11 +28,11 @@ use lemmy_db_schema::{
post,
},
source::{
comment::Comment,
comment::CommentWithoutId,
comment_reply::CommentReply,
community::{Community, CommunityFollower},
person::Person,
post::Post,
community::{CommunityWithoutId, CommunityFollower},
person::PersonWithoutId,
post::PostWithoutId,
},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
@ -42,11 +42,11 @@ use lemmy_db_schema::{
type CommentReplyViewTuple = (
CommentReply,
Comment,
Person,
Post,
Community,
Person,
CommentWithoutId,
PersonWithoutId,
PostWithoutId,
CommunityWithoutId,
PersonWithoutId,
CommentAggregatesNotInComment,
bool,
SubscribedType,
@ -107,11 +107,11 @@ fn queries<'a>() -> Queries<
)
.select((
comment_reply::all_columns,
comment::all_columns,
person::all_columns,
post::all_columns,
community::all_columns,
aliases::person1.fields(person::all_columns),
CommentWithoutId::as_select(),
PersonWithoutId::as_select(),
PostWithoutId::as_select(),
CommunityWithoutId::as_select(),
aliases::person1.fields(PersonWithoutId::as_select()),
CommentAggregatesNotInComment::as_select(),
community_person_ban::id.nullable().is_not_null(),
CommunityFollower::select_subscribed_type(),
@ -218,21 +218,35 @@ impl CommentReplyQuery {
impl JoinView for CommentReplyView {
type JoinTuple = CommentReplyViewTuple;
fn from_tuple(a: Self::JoinTuple) -> Self {
let counts = a.6.into_full(&a.1);
Self {
comment_reply: a.0,
comment: a.1,
creator: a.2,
post: a.3,
community: a.4,
recipient: a.5,
fn from_tuple(
(
comment_reply,
comment,
creator,
post,
community,
recipient,
counts,
creator_banned_from_community: a.7,
subscribed: a.8,
saved: a.9,
creator_blocked: a.10,
my_vote: a.11,
creator_banned_from_community,
subscribed,
saved,
creator_blocked,
my_vote,
): Self::JoinTuple,
) -> Self {
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_reply,
creator_banned_from_community,
subscribed,
saved,
creator_blocked,
my_vote,
}
}
}

View File

@ -29,11 +29,11 @@ use lemmy_db_schema::{
post,
},
source::{
comment::Comment,
community::{Community, CommunityFollower},
person::Person,
comment::CommentWithoutId,
community::{CommunityWithoutId, CommunityFollower},
person::PersonWithoutId,
person_mention::PersonMention,
post::Post,
post::PostWithoutId,
},
traits::JoinView,
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
@ -43,11 +43,11 @@ use lemmy_db_schema::{
type PersonMentionViewTuple = (
PersonMention,
Comment,
Person,
Post,
Community,
Person,
CommentWithoutId,
PersonWithoutId,
PostWithoutId,
CommunityWithoutId,
PersonWithoutId,
CommentAggregatesNotInComment,
bool,
SubscribedType,
@ -103,11 +103,11 @@ fn queries<'a>() -> Queries<
let selection = (
person_mention::all_columns,
comment::all_columns,
person::all_columns,
post::all_columns,
community::all_columns,
aliases::person1.fields(person::all_columns),
CommentWithoutId::as_select(),
PersonWithoutId::as_select(),
PostWithoutId::as_select(),
CommunityWithoutId::as_select(),
aliases::person1.fields(PersonWithoutId::as_select()),
CommentAggregatesNotInComment::as_select(),
community_person_ban::id.nullable().is_not_null(),
CommunityFollower::select_subscribed_type(),
@ -235,21 +235,35 @@ impl PersonMentionQuery {
impl JoinView for PersonMentionView {
type JoinTuple = PersonMentionViewTuple;
fn from_tuple(a: Self::JoinTuple) -> Self {
let counts = a.6.into_full(&a.1);
Self {
person_mention: a.0,
comment: a.1,
creator: a.2,
post: a.3,
community: a.4,
recipient: a.5,
fn from_tuple(
(
person_mention,
comment,
creator,
post,
community,
recipient,
counts,
creator_banned_from_community: a.7,
subscribed: a.8,
saved: a.9,
creator_blocked: a.10,
my_vote: a.11,
creator_banned_from_community,
subscribed,
saved,
creator_blocked,
my_vote,
): Self::JoinTuple,
) -> Self {
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),
person_mention,
creator_banned_from_community,
subscribed,
saved,
creator_blocked,
my_vote,
}
}
}