mirror of https://github.com/LemmyNet/lemmy.git
Reduce amount of columns selected (#3755)
* PostAggregatesNotInPost * CommentAggregatesNotInComment * CommunityPersonBanAdditionalInfo (partial) * Revert "CommunityPersonBanAdditionalInfo (partial)" This reverts commitreorder-woodpecker158f7f0cd9
. * Replace some nullable parts of selection with id::nullable().is_not_null() * CommunityFollower::select_subscribed_type * WithoutId * Add WithoutId derives * Update Cargo.toml * rerun ci * Fix syntatx errors * rerun ci * Add missing "|" in private_message_report_view.rs * rerun ci * cargo fmt * rerun ci * Only derive WithoutId for Community with "full" feature * rerun ci * Fix attribute filtering in WithoutId macro * rerun ci * Update without_id.rs * rerun ci * Update without_id.rs * rerun ci * Fix errors * rerun ci * cargo fmt * Fix errors * rerun ci * Move WithoutId to lib.rs * rerun ci * Remove macro_use for paste * rerun ci * Update comment_reply_view.rs * rerun ci * Update registration_application_view.rs * rerun ci * Revert "Update registration_application_view.rs" This reverts commit2e98e4bb83
. * Revert "Update comment_reply_view.rs" This reverts commit857bf9f5a2
. * Revert "Remove macro_use for paste" This reverts commit13247279ed
. * Revert "Move WithoutId to lib.rs" This reverts commit0c23e5213b
. * Revert "Fix errors" This reverts commita283d155e5
. * Revert "cargo fmt" This reverts commit36a5210352
. * Revert "Fix errors" This reverts commitc9102c14f4
. * Revert "Update without_id.rs" This reverts commit19adb2fcc8
. * Revert "Update without_id.rs" This reverts commite26107a2fe
. * Revert "Fix attribute filtering in WithoutId macro" This reverts commitacaa4902b0
. * Revert "Only derive WithoutId for Community with "full" feature" This reverts commitde0e9c6fdc
. * Revert "cargo fmt" This reverts commit5e1bd1ce58
. * Revert "Add missing "|" in private_message_report_view.rs" This reverts commitc7ae9f1cd5
. * Revert "Fix syntatx errors" This reverts commitd942f099de
. * Revert "Update Cargo.toml" This reverts commit23cdb6f6d3
. * Revert "Add WithoutId derives" This reverts commit06006d6ad3
. * Revert "WithoutId" This reverts commit5e86922b0f
. * Revert "CommentAggregatesNotInComment" This reverts commit603aede7ce
. * Revert "PostAggregatesNotInPost" This reverts commit1ee3fcaeab
. * Restore original position of options.saved_only filter * rerun ci * Update post_view.rs * rerun ci
parent
2ad3450004
commit
a47b12bbde
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
newtypes::{CommunityId, DbUrl, PersonId},
|
||||
schema::{community, instance},
|
||||
schema::{community, community_follower, instance},
|
||||
source::{
|
||||
actor_language::CommunityLanguage,
|
||||
community::{
|
||||
|
@ -19,7 +19,18 @@ use crate::{
|
|||
utils::{functions::lower, get_conn, DbPool},
|
||||
SubscribedType,
|
||||
};
|
||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||
use diesel::{
|
||||
deserialize,
|
||||
dsl,
|
||||
dsl::insert_into,
|
||||
pg::Pg,
|
||||
result::Error,
|
||||
sql_types,
|
||||
ExpressionMethods,
|
||||
NullableExpressionMethods,
|
||||
QueryDsl,
|
||||
Queryable,
|
||||
};
|
||||
use diesel_async::RunQueryDsl;
|
||||
|
||||
#[async_trait]
|
||||
|
@ -214,6 +225,21 @@ impl CommunityFollower {
|
|||
None => SubscribedType::NotSubscribed,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn select_subscribed_type() -> dsl::Nullable<community_follower::pending> {
|
||||
community_follower::pending.nullable()
|
||||
}
|
||||
}
|
||||
|
||||
impl Queryable<sql_types::Nullable<sql_types::Bool>, Pg> for SubscribedType {
|
||||
type Row = Option<bool>;
|
||||
fn build(row: Self::Row) -> deserialize::Result<Self> {
|
||||
Ok(match row {
|
||||
Some(true) => SubscribedType::Pending,
|
||||
Some(false) => SubscribedType::Subscribed,
|
||||
None => SubscribedType::NotSubscribed,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
|
|
@ -28,7 +28,7 @@ use lemmy_db_schema::{
|
|||
source::{
|
||||
comment::Comment,
|
||||
comment_report::CommentReport,
|
||||
community::{Community, CommunityPersonBan},
|
||||
community::Community,
|
||||
person::Person,
|
||||
post::Post,
|
||||
},
|
||||
|
@ -71,7 +71,7 @@ fn queries<'a>() -> Queries<
|
|||
person::all_columns,
|
||||
aliases::person1.fields(person::all_columns),
|
||||
comment_aggregates::all_columns,
|
||||
community_person_ban::all_columns.nullable(),
|
||||
community_person_ban::id.nullable().is_not_null(),
|
||||
comment_like::score.nullable(),
|
||||
aliases::person2.fields(person::all_columns).nullable(),
|
||||
);
|
||||
|
@ -228,7 +228,7 @@ impl JoinView for CommentReportView {
|
|||
Person,
|
||||
Person,
|
||||
CommentAggregates,
|
||||
Option<CommunityPersonBan>,
|
||||
bool,
|
||||
Option<i16>,
|
||||
Option<Person>,
|
||||
);
|
||||
|
@ -242,7 +242,7 @@ impl JoinView for CommentReportView {
|
|||
creator: a.4,
|
||||
comment_creator: a.5,
|
||||
counts: a.6,
|
||||
creator_banned_from_community: a.7.is_some(),
|
||||
creator_banned_from_community: a.7,
|
||||
my_vote: a.8,
|
||||
resolver: a.9,
|
||||
}
|
||||
|
|
|
@ -29,16 +29,16 @@ use lemmy_db_schema::{
|
|||
post,
|
||||
},
|
||||
source::{
|
||||
comment::{Comment, CommentSaved},
|
||||
community::{Community, CommunityFollower, CommunityPersonBan},
|
||||
comment::Comment,
|
||||
community::{Community, CommunityFollower},
|
||||
person::Person,
|
||||
person_block::PersonBlock,
|
||||
post::Post,
|
||||
},
|
||||
traits::JoinView,
|
||||
utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
|
||||
CommentSortType,
|
||||
ListingType,
|
||||
SubscribedType,
|
||||
};
|
||||
|
||||
type CommentViewTuple = (
|
||||
|
@ -47,10 +47,10 @@ type CommentViewTuple = (
|
|||
Post,
|
||||
Community,
|
||||
CommentAggregates,
|
||||
Option<CommunityPersonBan>,
|
||||
Option<CommunityFollower>,
|
||||
Option<CommentSaved>,
|
||||
Option<PersonBlock>,
|
||||
bool,
|
||||
SubscribedType,
|
||||
bool,
|
||||
bool,
|
||||
Option<i16>,
|
||||
);
|
||||
|
||||
|
@ -109,10 +109,10 @@ fn queries<'a>() -> Queries<
|
|||
post::all_columns,
|
||||
community::all_columns,
|
||||
comment_aggregates::all_columns,
|
||||
community_person_ban::all_columns.nullable(),
|
||||
community_follower::all_columns.nullable(),
|
||||
comment_saved::all_columns.nullable(),
|
||||
person_block::all_columns.nullable(),
|
||||
community_person_ban::id.nullable().is_not_null(),
|
||||
CommunityFollower::select_subscribed_type(),
|
||||
comment_saved::id.nullable().is_not_null(),
|
||||
person_block::id.nullable().is_not_null(),
|
||||
comment_like::score.nullable(),
|
||||
);
|
||||
|
||||
|
@ -171,9 +171,7 @@ fn queries<'a>() -> Queries<
|
|||
|
||||
if let Some(listing_type) = options.listing_type {
|
||||
match listing_type {
|
||||
ListingType::Subscribed => {
|
||||
query = query.filter(community_follower::person_id.is_not_null())
|
||||
} // TODO could be this: and(community_follower::person_id.eq(person_id_join)),
|
||||
ListingType::Subscribed => query = query.filter(community_follower::pending.is_not_null()), // TODO could be this: and(community_follower::person_id.eq(person_id_join)),
|
||||
ListingType::Local => {
|
||||
query = query.filter(community::local.eq(true)).filter(
|
||||
community::hidden
|
||||
|
@ -338,10 +336,10 @@ impl JoinView for CommentView {
|
|||
post: a.2,
|
||||
community: a.3,
|
||||
counts: a.4,
|
||||
creator_banned_from_community: a.5.is_some(),
|
||||
subscribed: CommunityFollower::to_subscribed_type(&a.6),
|
||||
saved: a.7.is_some(),
|
||||
creator_blocked: a.8.is_some(),
|
||||
creator_banned_from_community: a.5,
|
||||
subscribed: a.6,
|
||||
saved: a.7,
|
||||
creator_blocked: a.8,
|
||||
my_vote: a.9,
|
||||
}
|
||||
}
|
||||
|
@ -361,7 +359,6 @@ mod tests {
|
|||
Community,
|
||||
DbPool,
|
||||
Person,
|
||||
PersonBlock,
|
||||
Post,
|
||||
},
|
||||
structs::LocalUserView,
|
||||
|
@ -378,7 +375,7 @@ mod tests {
|
|||
language::Language,
|
||||
local_user::{LocalUser, LocalUserInsertForm},
|
||||
person::PersonInsertForm,
|
||||
person_block::PersonBlockForm,
|
||||
person_block::{PersonBlock, PersonBlockForm},
|
||||
post::PostInsertForm,
|
||||
},
|
||||
traits::{Blockable, Crud, Likeable},
|
||||
|
|
|
@ -23,12 +23,7 @@ use lemmy_db_schema::{
|
|||
post_like,
|
||||
post_report,
|
||||
},
|
||||
source::{
|
||||
community::{Community, CommunityPersonBan},
|
||||
person::Person,
|
||||
post::Post,
|
||||
post_report::PostReport,
|
||||
},
|
||||
source::{community::Community, person::Person, post::Post, post_report::PostReport},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
|
||||
};
|
||||
|
@ -39,7 +34,7 @@ type PostReportViewTuple = (
|
|||
Community,
|
||||
Person,
|
||||
Person,
|
||||
Option<CommunityPersonBan>,
|
||||
bool,
|
||||
Option<i16>,
|
||||
PostAggregates,
|
||||
Option<Person>,
|
||||
|
@ -80,7 +75,7 @@ fn queries<'a>() -> Queries<
|
|||
community::all_columns,
|
||||
person::all_columns,
|
||||
aliases::person1.fields(person::all_columns),
|
||||
community_person_ban::all_columns.nullable(),
|
||||
community_person_ban::id.nullable().is_not_null(),
|
||||
post_like::score.nullable(),
|
||||
post_aggregates::all_columns,
|
||||
aliases::person2.fields(person::all_columns.nullable()),
|
||||
|
@ -213,7 +208,7 @@ impl JoinView for PostReportView {
|
|||
community: a.2,
|
||||
creator: a.3,
|
||||
post_creator: a.4,
|
||||
creator_banned_from_community: a.5.is_some(),
|
||||
creator_banned_from_community: a.5,
|
||||
my_vote: a.6,
|
||||
counts: a.7,
|
||||
resolver: a.8,
|
||||
|
|
|
@ -34,15 +34,15 @@ use lemmy_db_schema::{
|
|||
post_saved,
|
||||
},
|
||||
source::{
|
||||
community::{Community, CommunityFollower, CommunityPersonBan},
|
||||
community::{Community, CommunityFollower},
|
||||
person::Person,
|
||||
person_block::PersonBlock,
|
||||
post::{Post, PostRead, PostSaved},
|
||||
post::Post,
|
||||
},
|
||||
traits::JoinView,
|
||||
utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
|
||||
ListingType,
|
||||
SortType,
|
||||
SubscribedType,
|
||||
};
|
||||
use tracing::debug;
|
||||
|
||||
|
@ -50,12 +50,12 @@ type PostViewTuple = (
|
|||
Post,
|
||||
Person,
|
||||
Community,
|
||||
Option<CommunityPersonBan>,
|
||||
bool,
|
||||
PostAggregates,
|
||||
Option<CommunityFollower>,
|
||||
Option<PostSaved>,
|
||||
Option<PostRead>,
|
||||
Option<PersonBlock>,
|
||||
SubscribedType,
|
||||
bool,
|
||||
bool,
|
||||
bool,
|
||||
Option<i16>,
|
||||
i64,
|
||||
);
|
||||
|
@ -136,12 +136,12 @@ fn queries<'a>() -> Queries<
|
|||
post::all_columns,
|
||||
person::all_columns,
|
||||
community::all_columns,
|
||||
community_person_ban::all_columns.nullable(),
|
||||
community_person_ban::id.nullable().is_not_null(),
|
||||
post_aggregates::all_columns,
|
||||
community_follower::all_columns.nullable(),
|
||||
post_saved::all_columns.nullable(),
|
||||
post_read::all_columns.nullable(),
|
||||
person_block::all_columns.nullable(),
|
||||
CommunityFollower::select_subscribed_type(),
|
||||
post_saved::id.nullable().is_not_null(),
|
||||
post_read::id.nullable().is_not_null(),
|
||||
person_block::id.nullable().is_not_null(),
|
||||
post_like::score.nullable(),
|
||||
coalesce(
|
||||
post_aggregates::comments.nullable() - person_post_aggregates::read_comments.nullable(),
|
||||
|
@ -242,9 +242,7 @@ fn queries<'a>() -> Queries<
|
|||
|
||||
if let Some(listing_type) = options.listing_type {
|
||||
match listing_type {
|
||||
ListingType::Subscribed => {
|
||||
query = query.filter(community_follower::person_id.is_not_null())
|
||||
}
|
||||
ListingType::Subscribed => query = query.filter(community_follower::pending.is_not_null()),
|
||||
ListingType::Local => {
|
||||
query = query.filter(community::local.eq(true)).filter(
|
||||
community::hidden
|
||||
|
@ -294,7 +292,7 @@ fn queries<'a>() -> Queries<
|
|||
};
|
||||
|
||||
if options.saved_only.unwrap_or(false) {
|
||||
query = query.filter(post_saved::post_id.is_not_null());
|
||||
query = query.filter(post_saved::id.is_not_null());
|
||||
}
|
||||
|
||||
if options.moderator_view.unwrap_or(false) {
|
||||
|
@ -453,12 +451,12 @@ impl JoinView for PostView {
|
|||
post: a.0,
|
||||
creator: a.1,
|
||||
community: a.2,
|
||||
creator_banned_from_community: a.3.is_some(),
|
||||
creator_banned_from_community: a.3,
|
||||
counts: a.4,
|
||||
subscribed: CommunityFollower::to_subscribed_type(&a.5),
|
||||
saved: a.6.is_some(),
|
||||
read: a.7.is_some(),
|
||||
creator_blocked: a.8.is_some(),
|
||||
subscribed: a.5,
|
||||
saved: a.6,
|
||||
read: a.7,
|
||||
creator_blocked: a.8,
|
||||
my_vote: a.9,
|
||||
unread_comments: a.10,
|
||||
}
|
||||
|
|
|
@ -27,16 +27,16 @@ use lemmy_db_schema::{
|
|||
post,
|
||||
},
|
||||
source::{
|
||||
comment::{Comment, CommentSaved},
|
||||
comment::Comment,
|
||||
comment_reply::CommentReply,
|
||||
community::{Community, CommunityFollower, CommunityPersonBan},
|
||||
community::{Community, CommunityFollower},
|
||||
person::Person,
|
||||
person_block::PersonBlock,
|
||||
post::Post,
|
||||
},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
|
||||
CommentSortType,
|
||||
SubscribedType,
|
||||
};
|
||||
|
||||
type CommentReplyViewTuple = (
|
||||
|
@ -47,10 +47,10 @@ type CommentReplyViewTuple = (
|
|||
Community,
|
||||
Person,
|
||||
CommentAggregates,
|
||||
Option<CommunityPersonBan>,
|
||||
Option<CommunityFollower>,
|
||||
Option<CommentSaved>,
|
||||
Option<PersonBlock>,
|
||||
bool,
|
||||
SubscribedType,
|
||||
bool,
|
||||
bool,
|
||||
Option<i16>,
|
||||
);
|
||||
|
||||
|
@ -112,10 +112,10 @@ fn queries<'a>() -> Queries<
|
|||
community::all_columns,
|
||||
aliases::person1.fields(person::all_columns),
|
||||
comment_aggregates::all_columns,
|
||||
community_person_ban::all_columns.nullable(),
|
||||
community_follower::all_columns.nullable(),
|
||||
comment_saved::all_columns.nullable(),
|
||||
person_block::all_columns.nullable(),
|
||||
community_person_ban::id.nullable().is_not_null(),
|
||||
CommunityFollower::select_subscribed_type(),
|
||||
comment_saved::id.nullable().is_not_null(),
|
||||
person_block::id.nullable().is_not_null(),
|
||||
comment_like::score.nullable(),
|
||||
))
|
||||
};
|
||||
|
@ -226,10 +226,10 @@ impl JoinView for CommentReplyView {
|
|||
community: a.4,
|
||||
recipient: a.5,
|
||||
counts: a.6,
|
||||
creator_banned_from_community: a.7.is_some(),
|
||||
subscribed: CommunityFollower::to_subscribed_type(&a.8),
|
||||
saved: a.9.is_some(),
|
||||
creator_blocked: a.10.is_some(),
|
||||
creator_banned_from_community: a.7,
|
||||
subscribed: a.8,
|
||||
saved: a.9,
|
||||
creator_blocked: a.10,
|
||||
my_vote: a.11,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,21 +16,16 @@ use lemmy_db_schema::{
|
|||
schema::{community, community_aggregates, community_block, community_follower, local_user},
|
||||
source::{
|
||||
community::{Community, CommunityFollower},
|
||||
community_block::CommunityBlock,
|
||||
local_user::LocalUser,
|
||||
},
|
||||
traits::JoinView,
|
||||
utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
|
||||
ListingType,
|
||||
SortType,
|
||||
SubscribedType,
|
||||
};
|
||||
|
||||
type CommunityViewTuple = (
|
||||
Community,
|
||||
CommunityAggregates,
|
||||
Option<CommunityFollower>,
|
||||
Option<CommunityBlock>,
|
||||
);
|
||||
type CommunityViewTuple = (Community, CommunityAggregates, SubscribedType, bool);
|
||||
|
||||
fn queries<'a>() -> Queries<
|
||||
impl ReadFn<'a, CommunityView, (CommunityId, Option<PersonId>, Option<bool>)>,
|
||||
|
@ -61,8 +56,8 @@ fn queries<'a>() -> Queries<
|
|||
let selection = (
|
||||
community::all_columns,
|
||||
community_aggregates::all_columns,
|
||||
community_follower::all_columns.nullable(),
|
||||
community_block::all_columns.nullable(),
|
||||
CommunityFollower::select_subscribed_type(),
|
||||
community_block::id.nullable().is_not_null(),
|
||||
);
|
||||
|
||||
let not_removed_or_deleted = community::removed
|
||||
|
@ -138,7 +133,7 @@ fn queries<'a>() -> Queries<
|
|||
|
||||
if let Some(listing_type) = options.listing_type {
|
||||
query = match listing_type {
|
||||
ListingType::Subscribed => query.filter(community_follower::person_id.is_not_null()), // TODO could be this: and(community_follower::person_id.eq(person_id_join)),
|
||||
ListingType::Subscribed => query.filter(community_follower::pending.is_not_null()), // TODO could be this: and(community_follower::person_id.eq(person_id_join)),
|
||||
ListingType::Local => query.filter(community::local.eq(true)),
|
||||
_ => query,
|
||||
};
|
||||
|
@ -217,8 +212,8 @@ impl JoinView for CommunityView {
|
|||
Self {
|
||||
community: a.0,
|
||||
counts: a.1,
|
||||
subscribed: CommunityFollower::to_subscribed_type(&a.2),
|
||||
blocked: a.3.is_some(),
|
||||
subscribed: a.2,
|
||||
blocked: a.3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,16 +28,16 @@ use lemmy_db_schema::{
|
|||
post,
|
||||
},
|
||||
source::{
|
||||
comment::{Comment, CommentSaved},
|
||||
community::{Community, CommunityFollower, CommunityPersonBan},
|
||||
comment::Comment,
|
||||
community::{Community, CommunityFollower},
|
||||
person::Person,
|
||||
person_block::PersonBlock,
|
||||
person_mention::PersonMention,
|
||||
post::Post,
|
||||
},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
|
||||
CommentSortType,
|
||||
SubscribedType,
|
||||
};
|
||||
|
||||
type PersonMentionViewTuple = (
|
||||
|
@ -48,10 +48,10 @@ type PersonMentionViewTuple = (
|
|||
Community,
|
||||
Person,
|
||||
CommentAggregates,
|
||||
Option<CommunityPersonBan>,
|
||||
Option<CommunityFollower>,
|
||||
Option<CommentSaved>,
|
||||
Option<PersonBlock>,
|
||||
bool,
|
||||
SubscribedType,
|
||||
bool,
|
||||
bool,
|
||||
Option<i16>,
|
||||
);
|
||||
|
||||
|
@ -108,10 +108,10 @@ fn queries<'a>() -> Queries<
|
|||
community::all_columns,
|
||||
aliases::person1.fields(person::all_columns),
|
||||
comment_aggregates::all_columns,
|
||||
community_person_ban::all_columns.nullable(),
|
||||
community_follower::all_columns.nullable(),
|
||||
comment_saved::all_columns.nullable(),
|
||||
person_block::all_columns.nullable(),
|
||||
community_person_ban::id.nullable().is_not_null(),
|
||||
CommunityFollower::select_subscribed_type(),
|
||||
comment_saved::id.nullable().is_not_null(),
|
||||
person_block::id.nullable().is_not_null(),
|
||||
comment_like::score.nullable(),
|
||||
);
|
||||
|
||||
|
@ -243,10 +243,10 @@ impl JoinView for PersonMentionView {
|
|||
community: a.4,
|
||||
recipient: a.5,
|
||||
counts: a.6,
|
||||
creator_banned_from_community: a.7.is_some(),
|
||||
subscribed: CommunityFollower::to_subscribed_type(&a.8),
|
||||
saved: a.9.is_some(),
|
||||
creator_blocked: a.10.is_some(),
|
||||
creator_banned_from_community: a.7,
|
||||
subscribed: a.8,
|
||||
saved: a.9,
|
||||
creator_blocked: a.10,
|
||||
my_vote: a.11,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue