Reduce amount of columns selected (#3755)

* PostAggregatesNotInPost

* CommentAggregatesNotInComment

* CommunityPersonBanAdditionalInfo (partial)

* Revert "CommunityPersonBanAdditionalInfo (partial)"

This reverts commit 158f7f0cd9.

* 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 commit 2e98e4bb83.

* Revert "Update comment_reply_view.rs"

This reverts commit 857bf9f5a2.

* Revert "Remove macro_use for paste"

This reverts commit 13247279ed.

* Revert "Move WithoutId to lib.rs"

This reverts commit 0c23e5213b.

* Revert "Fix errors"

This reverts commit a283d155e5.

* Revert "cargo fmt"

This reverts commit 36a5210352.

* Revert "Fix errors"

This reverts commit c9102c14f4.

* Revert "Update without_id.rs"

This reverts commit 19adb2fcc8.

* Revert "Update without_id.rs"

This reverts commit e26107a2fe.

* Revert "Fix attribute filtering in WithoutId macro"

This reverts commit acaa4902b0.

* Revert "Only derive WithoutId for Community with "full" feature"

This reverts commit de0e9c6fdc.

* Revert "cargo fmt"

This reverts commit 5e1bd1ce58.

* Revert "Add missing "|" in private_message_report_view.rs"

This reverts commit c7ae9f1cd5.

* Revert "Fix syntatx errors"

This reverts commit d942f099de.

* Revert "Update Cargo.toml"

This reverts commit 23cdb6f6d3.

* Revert "Add WithoutId derives"

This reverts commit 06006d6ad3.

* Revert "WithoutId"

This reverts commit 5e86922b0f.

* Revert "CommentAggregatesNotInComment"

This reverts commit 603aede7ce.

* Revert "PostAggregatesNotInPost"

This reverts commit 1ee3fcaeab.

* Restore original position of options.saved_only filter

* rerun ci

* Update post_view.rs

* rerun ci
This commit is contained in:
dullbananas 2023-08-08 02:41:10 -07:00 committed by GitHub
parent 2ad3450004
commit a47b12bbde
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 110 additions and 99 deletions

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
newtypes::{CommunityId, DbUrl, PersonId}, newtypes::{CommunityId, DbUrl, PersonId},
schema::{community, instance}, schema::{community, community_follower, instance},
source::{ source::{
actor_language::CommunityLanguage, actor_language::CommunityLanguage,
community::{ community::{
@ -19,7 +19,18 @@ use crate::{
utils::{functions::lower, get_conn, DbPool}, utils::{functions::lower, get_conn, DbPool},
SubscribedType, 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; use diesel_async::RunQueryDsl;
#[async_trait] #[async_trait]
@ -214,6 +225,21 @@ impl CommunityFollower {
None => SubscribedType::NotSubscribed, 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] #[async_trait]

View file

@ -28,7 +28,7 @@ use lemmy_db_schema::{
source::{ source::{
comment::Comment, comment::Comment,
comment_report::CommentReport, comment_report::CommentReport,
community::{Community, CommunityPersonBan}, community::Community,
person::Person, person::Person,
post::Post, post::Post,
}, },
@ -71,7 +71,7 @@ fn queries<'a>() -> Queries<
person::all_columns, person::all_columns,
aliases::person1.fields(person::all_columns), aliases::person1.fields(person::all_columns),
comment_aggregates::all_columns, comment_aggregates::all_columns,
community_person_ban::all_columns.nullable(), community_person_ban::id.nullable().is_not_null(),
comment_like::score.nullable(), comment_like::score.nullable(),
aliases::person2.fields(person::all_columns).nullable(), aliases::person2.fields(person::all_columns).nullable(),
); );
@ -228,7 +228,7 @@ impl JoinView for CommentReportView {
Person, Person,
Person, Person,
CommentAggregates, CommentAggregates,
Option<CommunityPersonBan>, bool,
Option<i16>, Option<i16>,
Option<Person>, Option<Person>,
); );
@ -242,7 +242,7 @@ impl JoinView for CommentReportView {
creator: a.4, creator: a.4,
comment_creator: a.5, comment_creator: a.5,
counts: a.6, counts: a.6,
creator_banned_from_community: a.7.is_some(), creator_banned_from_community: a.7,
my_vote: a.8, my_vote: a.8,
resolver: a.9, resolver: a.9,
} }

View file

@ -29,16 +29,16 @@ use lemmy_db_schema::{
post, post,
}, },
source::{ source::{
comment::{Comment, CommentSaved}, comment::Comment,
community::{Community, CommunityFollower, CommunityPersonBan}, community::{Community, CommunityFollower},
person::Person, person::Person,
person_block::PersonBlock,
post::Post, post::Post,
}, },
traits::JoinView, traits::JoinView,
utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
CommentSortType, CommentSortType,
ListingType, ListingType,
SubscribedType,
}; };
type CommentViewTuple = ( type CommentViewTuple = (
@ -47,10 +47,10 @@ type CommentViewTuple = (
Post, Post,
Community, Community,
CommentAggregates, CommentAggregates,
Option<CommunityPersonBan>, bool,
Option<CommunityFollower>, SubscribedType,
Option<CommentSaved>, bool,
Option<PersonBlock>, bool,
Option<i16>, Option<i16>,
); );
@ -109,10 +109,10 @@ fn queries<'a>() -> Queries<
post::all_columns, post::all_columns,
community::all_columns, community::all_columns,
comment_aggregates::all_columns, comment_aggregates::all_columns,
community_person_ban::all_columns.nullable(), community_person_ban::id.nullable().is_not_null(),
community_follower::all_columns.nullable(), CommunityFollower::select_subscribed_type(),
comment_saved::all_columns.nullable(), comment_saved::id.nullable().is_not_null(),
person_block::all_columns.nullable(), person_block::id.nullable().is_not_null(),
comment_like::score.nullable(), comment_like::score.nullable(),
); );
@ -171,9 +171,7 @@ fn queries<'a>() -> Queries<
if let Some(listing_type) = options.listing_type { if let Some(listing_type) = options.listing_type {
match listing_type { match listing_type {
ListingType::Subscribed => { ListingType::Subscribed => query = query.filter(community_follower::pending.is_not_null()), // TODO could be this: and(community_follower::person_id.eq(person_id_join)),
query = query.filter(community_follower::person_id.is_not_null())
} // TODO could be this: and(community_follower::person_id.eq(person_id_join)),
ListingType::Local => { ListingType::Local => {
query = query.filter(community::local.eq(true)).filter( query = query.filter(community::local.eq(true)).filter(
community::hidden community::hidden
@ -338,10 +336,10 @@ impl JoinView for CommentView {
post: a.2, post: a.2,
community: a.3, community: a.3,
counts: a.4, counts: a.4,
creator_banned_from_community: a.5.is_some(), creator_banned_from_community: a.5,
subscribed: CommunityFollower::to_subscribed_type(&a.6), subscribed: a.6,
saved: a.7.is_some(), saved: a.7,
creator_blocked: a.8.is_some(), creator_blocked: a.8,
my_vote: a.9, my_vote: a.9,
} }
} }
@ -361,7 +359,6 @@ mod tests {
Community, Community,
DbPool, DbPool,
Person, Person,
PersonBlock,
Post, Post,
}, },
structs::LocalUserView, structs::LocalUserView,
@ -378,7 +375,7 @@ mod tests {
language::Language, language::Language,
local_user::{LocalUser, LocalUserInsertForm}, local_user::{LocalUser, LocalUserInsertForm},
person::PersonInsertForm, person::PersonInsertForm,
person_block::PersonBlockForm, person_block::{PersonBlock, PersonBlockForm},
post::PostInsertForm, post::PostInsertForm,
}, },
traits::{Blockable, Crud, Likeable}, traits::{Blockable, Crud, Likeable},

View file

@ -23,12 +23,7 @@ use lemmy_db_schema::{
post_like, post_like,
post_report, post_report,
}, },
source::{ source::{community::Community, person::Person, post::Post, post_report::PostReport},
community::{Community, CommunityPersonBan},
person::Person,
post::Post,
post_report::PostReport,
},
traits::JoinView, traits::JoinView,
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
}; };
@ -39,7 +34,7 @@ type PostReportViewTuple = (
Community, Community,
Person, Person,
Person, Person,
Option<CommunityPersonBan>, bool,
Option<i16>, Option<i16>,
PostAggregates, PostAggregates,
Option<Person>, Option<Person>,
@ -80,7 +75,7 @@ fn queries<'a>() -> Queries<
community::all_columns, community::all_columns,
person::all_columns, person::all_columns,
aliases::person1.fields(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_like::score.nullable(),
post_aggregates::all_columns, post_aggregates::all_columns,
aliases::person2.fields(person::all_columns.nullable()), aliases::person2.fields(person::all_columns.nullable()),
@ -213,7 +208,7 @@ impl JoinView for PostReportView {
community: a.2, community: a.2,
creator: a.3, creator: a.3,
post_creator: a.4, post_creator: a.4,
creator_banned_from_community: a.5.is_some(), creator_banned_from_community: a.5,
my_vote: a.6, my_vote: a.6,
counts: a.7, counts: a.7,
resolver: a.8, resolver: a.8,

View file

@ -34,15 +34,15 @@ use lemmy_db_schema::{
post_saved, post_saved,
}, },
source::{ source::{
community::{Community, CommunityFollower, CommunityPersonBan}, community::{Community, CommunityFollower},
person::Person, person::Person,
person_block::PersonBlock, post::Post,
post::{Post, PostRead, PostSaved},
}, },
traits::JoinView, traits::JoinView,
utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
ListingType, ListingType,
SortType, SortType,
SubscribedType,
}; };
use tracing::debug; use tracing::debug;
@ -50,12 +50,12 @@ type PostViewTuple = (
Post, Post,
Person, Person,
Community, Community,
Option<CommunityPersonBan>, bool,
PostAggregates, PostAggregates,
Option<CommunityFollower>, SubscribedType,
Option<PostSaved>, bool,
Option<PostRead>, bool,
Option<PersonBlock>, bool,
Option<i16>, Option<i16>,
i64, i64,
); );
@ -136,12 +136,12 @@ fn queries<'a>() -> Queries<
post::all_columns, post::all_columns,
person::all_columns, person::all_columns,
community::all_columns, community::all_columns,
community_person_ban::all_columns.nullable(), community_person_ban::id.nullable().is_not_null(),
post_aggregates::all_columns, post_aggregates::all_columns,
community_follower::all_columns.nullable(), CommunityFollower::select_subscribed_type(),
post_saved::all_columns.nullable(), post_saved::id.nullable().is_not_null(),
post_read::all_columns.nullable(), post_read::id.nullable().is_not_null(),
person_block::all_columns.nullable(), person_block::id.nullable().is_not_null(),
post_like::score.nullable(), post_like::score.nullable(),
coalesce( coalesce(
post_aggregates::comments.nullable() - person_post_aggregates::read_comments.nullable(), 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 { if let Some(listing_type) = options.listing_type {
match listing_type { match listing_type {
ListingType::Subscribed => { ListingType::Subscribed => query = query.filter(community_follower::pending.is_not_null()),
query = query.filter(community_follower::person_id.is_not_null())
}
ListingType::Local => { ListingType::Local => {
query = query.filter(community::local.eq(true)).filter( query = query.filter(community::local.eq(true)).filter(
community::hidden community::hidden
@ -294,7 +292,7 @@ fn queries<'a>() -> Queries<
}; };
if options.saved_only.unwrap_or(false) { 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) { if options.moderator_view.unwrap_or(false) {
@ -453,12 +451,12 @@ impl JoinView for PostView {
post: a.0, post: a.0,
creator: a.1, creator: a.1,
community: a.2, community: a.2,
creator_banned_from_community: a.3.is_some(), creator_banned_from_community: a.3,
counts: a.4, counts: a.4,
subscribed: CommunityFollower::to_subscribed_type(&a.5), subscribed: a.5,
saved: a.6.is_some(), saved: a.6,
read: a.7.is_some(), read: a.7,
creator_blocked: a.8.is_some(), creator_blocked: a.8,
my_vote: a.9, my_vote: a.9,
unread_comments: a.10, unread_comments: a.10,
} }

View file

@ -27,16 +27,16 @@ use lemmy_db_schema::{
post, post,
}, },
source::{ source::{
comment::{Comment, CommentSaved}, comment::Comment,
comment_reply::CommentReply, comment_reply::CommentReply,
community::{Community, CommunityFollower, CommunityPersonBan}, community::{Community, CommunityFollower},
person::Person, person::Person,
person_block::PersonBlock,
post::Post, post::Post,
}, },
traits::JoinView, traits::JoinView,
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
CommentSortType, CommentSortType,
SubscribedType,
}; };
type CommentReplyViewTuple = ( type CommentReplyViewTuple = (
@ -47,10 +47,10 @@ type CommentReplyViewTuple = (
Community, Community,
Person, Person,
CommentAggregates, CommentAggregates,
Option<CommunityPersonBan>, bool,
Option<CommunityFollower>, SubscribedType,
Option<CommentSaved>, bool,
Option<PersonBlock>, bool,
Option<i16>, Option<i16>,
); );
@ -112,10 +112,10 @@ fn queries<'a>() -> Queries<
community::all_columns, community::all_columns,
aliases::person1.fields(person::all_columns), aliases::person1.fields(person::all_columns),
comment_aggregates::all_columns, comment_aggregates::all_columns,
community_person_ban::all_columns.nullable(), community_person_ban::id.nullable().is_not_null(),
community_follower::all_columns.nullable(), CommunityFollower::select_subscribed_type(),
comment_saved::all_columns.nullable(), comment_saved::id.nullable().is_not_null(),
person_block::all_columns.nullable(), person_block::id.nullable().is_not_null(),
comment_like::score.nullable(), comment_like::score.nullable(),
)) ))
}; };
@ -226,10 +226,10 @@ impl JoinView for CommentReplyView {
community: a.4, community: a.4,
recipient: a.5, recipient: a.5,
counts: a.6, counts: a.6,
creator_banned_from_community: a.7.is_some(), creator_banned_from_community: a.7,
subscribed: CommunityFollower::to_subscribed_type(&a.8), subscribed: a.8,
saved: a.9.is_some(), saved: a.9,
creator_blocked: a.10.is_some(), creator_blocked: a.10,
my_vote: a.11, my_vote: a.11,
} }
} }

View file

@ -16,21 +16,16 @@ use lemmy_db_schema::{
schema::{community, community_aggregates, community_block, community_follower, local_user}, schema::{community, community_aggregates, community_block, community_follower, local_user},
source::{ source::{
community::{Community, CommunityFollower}, community::{Community, CommunityFollower},
community_block::CommunityBlock,
local_user::LocalUser, local_user::LocalUser,
}, },
traits::JoinView, traits::JoinView,
utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
ListingType, ListingType,
SortType, SortType,
SubscribedType,
}; };
type CommunityViewTuple = ( type CommunityViewTuple = (Community, CommunityAggregates, SubscribedType, bool);
Community,
CommunityAggregates,
Option<CommunityFollower>,
Option<CommunityBlock>,
);
fn queries<'a>() -> Queries< fn queries<'a>() -> Queries<
impl ReadFn<'a, CommunityView, (CommunityId, Option<PersonId>, Option<bool>)>, impl ReadFn<'a, CommunityView, (CommunityId, Option<PersonId>, Option<bool>)>,
@ -61,8 +56,8 @@ fn queries<'a>() -> Queries<
let selection = ( let selection = (
community::all_columns, community::all_columns,
community_aggregates::all_columns, community_aggregates::all_columns,
community_follower::all_columns.nullable(), CommunityFollower::select_subscribed_type(),
community_block::all_columns.nullable(), community_block::id.nullable().is_not_null(),
); );
let not_removed_or_deleted = community::removed let not_removed_or_deleted = community::removed
@ -138,7 +133,7 @@ fn queries<'a>() -> Queries<
if let Some(listing_type) = options.listing_type { if let Some(listing_type) = options.listing_type {
query = match 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)), ListingType::Local => query.filter(community::local.eq(true)),
_ => query, _ => query,
}; };
@ -217,8 +212,8 @@ impl JoinView for CommunityView {
Self { Self {
community: a.0, community: a.0,
counts: a.1, counts: a.1,
subscribed: CommunityFollower::to_subscribed_type(&a.2), subscribed: a.2,
blocked: a.3.is_some(), blocked: a.3,
} }
} }
} }

View file

@ -28,16 +28,16 @@ use lemmy_db_schema::{
post, post,
}, },
source::{ source::{
comment::{Comment, CommentSaved}, comment::Comment,
community::{Community, CommunityFollower, CommunityPersonBan}, community::{Community, CommunityFollower},
person::Person, person::Person,
person_block::PersonBlock,
person_mention::PersonMention, person_mention::PersonMention,
post::Post, post::Post,
}, },
traits::JoinView, traits::JoinView,
utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, utils::{get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
CommentSortType, CommentSortType,
SubscribedType,
}; };
type PersonMentionViewTuple = ( type PersonMentionViewTuple = (
@ -48,10 +48,10 @@ type PersonMentionViewTuple = (
Community, Community,
Person, Person,
CommentAggregates, CommentAggregates,
Option<CommunityPersonBan>, bool,
Option<CommunityFollower>, SubscribedType,
Option<CommentSaved>, bool,
Option<PersonBlock>, bool,
Option<i16>, Option<i16>,
); );
@ -108,10 +108,10 @@ fn queries<'a>() -> Queries<
community::all_columns, community::all_columns,
aliases::person1.fields(person::all_columns), aliases::person1.fields(person::all_columns),
comment_aggregates::all_columns, comment_aggregates::all_columns,
community_person_ban::all_columns.nullable(), community_person_ban::id.nullable().is_not_null(),
community_follower::all_columns.nullable(), CommunityFollower::select_subscribed_type(),
comment_saved::all_columns.nullable(), comment_saved::id.nullable().is_not_null(),
person_block::all_columns.nullable(), person_block::id.nullable().is_not_null(),
comment_like::score.nullable(), comment_like::score.nullable(),
); );
@ -243,10 +243,10 @@ impl JoinView for PersonMentionView {
community: a.4, community: a.4,
recipient: a.5, recipient: a.5,
counts: a.6, counts: a.6,
creator_banned_from_community: a.7.is_some(), creator_banned_from_community: a.7,
subscribed: CommunityFollower::to_subscribed_type(&a.8), subscribed: a.8,
saved: a.9.is_some(), saved: a.9,
creator_blocked: a.10.is_some(), creator_blocked: a.10,
my_vote: a.11, my_vote: a.11,
} }
} }