From: dullbananas Date: Tue, 8 Aug 2023 09:41:10 +0000 (-0700) Subject: Reduce amount of columns selected (#3755) X-Git-Url: http://these/git/%24%7Bsubmission.url%7D?a=commitdiff_plain;h=a47b12bbdee274c761a912cde0baddb715674023;p=lemmy.git Reduce amount of columns selected (#3755) * PostAggregatesNotInPost * CommentAggregatesNotInComment * CommunityPersonBanAdditionalInfo (partial) * Revert "CommunityPersonBanAdditionalInfo (partial)" This reverts commit 158f7f0cd9a07392fb1f457ac43c8d7c57e4190d. * 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 2e98e4bb8385b4630ed2d1dfdd8da9a35c0126b2. * Revert "Update comment_reply_view.rs" This reverts commit 857bf9f5a2413ff0e6e6c95e1157e8ce6bf9c0c3. * Revert "Remove macro_use for paste" This reverts commit 13247279ed9090f2d3c5c6525b9611529217d605. * Revert "Move WithoutId to lib.rs" This reverts commit 0c23e5213be1366bb64029e2007e97194e126676. * Revert "Fix errors" This reverts commit a283d155e5622bba0b6df8b07649fc246df8bb77. * Revert "cargo fmt" This reverts commit 36a5210352809b3ca417ec3b869ae4baaca17e16. * Revert "Fix errors" This reverts commit c9102c14f466a5d6175732625e74183579ee2be5. * Revert "Update without_id.rs" This reverts commit 19adb2fcc805f92f6720a439f3b2c80a2b866938. * Revert "Update without_id.rs" This reverts commit e26107a2fe30cc2ec81797830e3a34a1676619e4. * Revert "Fix attribute filtering in WithoutId macro" This reverts commit acaa4902b0e7e33205c5d287cd22b83732a1a401. * Revert "Only derive WithoutId for Community with "full" feature" This reverts commit de0e9c6fdc3c9344998d9d72e5e361a7f009c829. * Revert "cargo fmt" This reverts commit 5e1bd1ce58e997e9431f212fd2ee0283faaf6da3. * Revert "Add missing "|" in private_message_report_view.rs" This reverts commit c7ae9f1cd50dfead0fbc363d93692f82274ff870. * Revert "Fix syntatx errors" This reverts commit d942f099de8128b5a02fe74f5af43a4453a06350. * Revert "Update Cargo.toml" This reverts commit 23cdb6f6d3df6d2db06173f066c117a0c96dd8e1. * Revert "Add WithoutId derives" This reverts commit 06006d6ad338e946410962f4276f67fe5096ad5a. * Revert "WithoutId" This reverts commit 5e86922b0fd5bf08d114a8eee5d1e10b2ea534ee. * Revert "CommentAggregatesNotInComment" This reverts commit 603aede7cecacd246664f7f3f0047202f80d9938. * Revert "PostAggregatesNotInPost" This reverts commit 1ee3fcaeab8705e4e0e849ae6b93b45716aa9cc0. * Restore original position of options.saved_only filter * rerun ci * Update post_view.rs * rerun ci --- diff --git a/crates/db_schema/src/impls/community.rs b/crates/db_schema/src/impls/community.rs index 2d0fcfe5..d5d558fa 100644 --- a/crates/db_schema/src/impls/community.rs +++ b/crates/db_schema/src/impls/community.rs @@ -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.nullable() + } +} + +impl Queryable, Pg> for SubscribedType { + type Row = Option; + fn build(row: Self::Row) -> deserialize::Result { + Ok(match row { + Some(true) => SubscribedType::Pending, + Some(false) => SubscribedType::Subscribed, + None => SubscribedType::NotSubscribed, + }) + } } #[async_trait] diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index a92b3806..1b943eab 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -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, + bool, Option, Option, ); @@ -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, } diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 506efb32..f4f26dd2 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -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, - Option, - Option, - Option, + bool, + SubscribedType, + bool, + bool, Option, ); @@ -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}, diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index 4ef6067f..83526a1b 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -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, + bool, Option, PostAggregates, Option, @@ -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, diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index a832e111..5fcb73f6 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -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, + bool, PostAggregates, - Option, - Option, - Option, - Option, + SubscribedType, + bool, + bool, + bool, Option, 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, } diff --git a/crates/db_views_actor/src/comment_reply_view.rs b/crates/db_views_actor/src/comment_reply_view.rs index 86934520..ad5b0875 100644 --- a/crates/db_views_actor/src/comment_reply_view.rs +++ b/crates/db_views_actor/src/comment_reply_view.rs @@ -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, - Option, - Option, - Option, + bool, + SubscribedType, + bool, + bool, Option, ); @@ -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, } } diff --git a/crates/db_views_actor/src/community_view.rs b/crates/db_views_actor/src/community_view.rs index 9ca5c218..28a49257 100644 --- a/crates/db_views_actor/src/community_view.rs +++ b/crates/db_views_actor/src/community_view.rs @@ -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, - Option, -); +type CommunityViewTuple = (Community, CommunityAggregates, SubscribedType, bool); fn queries<'a>() -> Queries< impl ReadFn<'a, CommunityView, (CommunityId, Option, Option)>, @@ -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, } } } diff --git a/crates/db_views_actor/src/person_mention_view.rs b/crates/db_views_actor/src/person_mention_view.rs index 6528ab5d..0d8aed27 100644 --- a/crates/db_views_actor/src/person_mention_view.rs +++ b/crates/db_views_actor/src/person_mention_view.rs @@ -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, - Option, - Option, - Option, + bool, + SubscribedType, + bool, + bool, Option, ); @@ -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, } }