From 2f3f6bb3c9ae005fc6c29692a6d45870d65c48b6 Mon Sep 17 00:00:00 2001 From: dull b Date: Sun, 30 Jul 2023 00:12:20 +0000 Subject: [PATCH] Replace some nullable parts of selection with id::nullable().is_not_null() --- crates/db_views/src/comment_report_view.rs | 8 ++-- crates/db_views/src/comment_view.rs | 23 +++++----- crates/db_views/src/post_report_view.rs | 13 ++---- crates/db_views/src/post_view.rs | 42 +++++++++---------- .../db_views_actor/src/comment_reply_view.rs | 23 +++++----- crates/db_views_actor/src/community_view.rs | 7 ++-- .../db_views_actor/src/person_mention_view.rs | 23 +++++----- 7 files changed, 65 insertions(+), 74 deletions(-) diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index 3ee3934b5..5cf48e350 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -29,7 +29,7 @@ use lemmy_db_schema::{ source::{ comment::Comment, comment_report::CommentReport, - community::{Community, CommunityPersonBan}, + community::Community, person::Person, post::Post, }, @@ -72,7 +72,7 @@ fn queries<'a>() -> Queries< person::all_columns, aliases::person1.fields(person::all_columns), CommentAggregatesNotInComment::as_select(), - 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(), ); @@ -229,7 +229,7 @@ impl JoinView for CommentReportView { Person, Person, CommentAggregatesNotInComment, - Option, + bool, Option, Option, ); @@ -244,7 +244,7 @@ impl JoinView for CommentReportView { creator: a.4, comment_creator: a.5, counts, - 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 f126bfd2a..007359be2 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -30,10 +30,9 @@ 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, @@ -48,10 +47,10 @@ type CommentViewTuple = ( Post, Community, CommentAggregatesNotInComment, - Option, + bool, Option, - Option, - Option, + bool, + bool, Option, ); @@ -110,10 +109,10 @@ fn queries<'a>() -> Queries< post::all_columns, community::all_columns, CommentAggregatesNotInComment::as_select(), - community_person_ban::all_columns.nullable(), + community_person_ban::id.nullable().is_not_null(), community_follower::all_columns.nullable(), - comment_saved::all_columns.nullable(), - person_block::all_columns.nullable(), + comment_saved::id.nullable().is_not_null(), + person_block::id.nullable().is_not_null(), comment_like::score.nullable(), ); @@ -334,10 +333,10 @@ impl JoinView for CommentView { post: a.2, community: a.3, counts, - creator_banned_from_community: a.5.is_some(), + creator_banned_from_community: a.5, subscribed: CommunityFollower::to_subscribed_type(&a.6), - saved: a.7.is_some(), - creator_blocked: a.8.is_some(), + saved: a.7, + creator_blocked: a.8, my_vote: a.9, } } diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index 2d31fd0b2..b2c326c0e 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -24,12 +24,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}, }; @@ -40,7 +35,7 @@ type PostReportViewTuple = ( Community, Person, Person, - Option, + bool, Option, PostAggregatesNotInPost, Option, @@ -81,7 +76,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(), PostAggregatesNotInPost::as_select(), aliases::person2.fields(person::all_columns.nullable()), @@ -215,7 +210,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, resolver: a.8, diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 519463265..df62fccfa 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -35,10 +35,9 @@ 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}, @@ -51,12 +50,12 @@ type PostViewTuple = ( Post, Person, Community, - Option, + bool, PostAggregatesNotInPost, Option, - Option, - Option, - Option, + bool, + bool, + bool, Option, i64, ); @@ -137,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(), PostAggregatesNotInPost::as_select(), community_follower::all_columns.nullable(), - post_saved::all_columns.nullable(), - post_read::all_columns.nullable(), - person_block::all_columns.nullable(), + 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(), @@ -210,8 +209,13 @@ fn queries<'a>() -> Queries< .eq(local_user_language::language_id) .and(local_user_language::local_user_id.eq(local_user_id_join)), ), - ) - .select(selection); + ); + + if options.saved_only.unwrap_or(false) { + query = query.filter(post_saved::id.is_not_null()); + } + + let mut query = query.select(selection); let is_profile_view = options.is_profile_view.unwrap_or(false); let is_creator = options.creator_id == options.local_user.map(|l| l.person.id); @@ -295,10 +299,6 @@ fn queries<'a>() -> Queries< query = query.filter(person::bot_account.eq(false)); }; - if options.saved_only.unwrap_or(false) { - query = query.filter(post_saved::post_id.is_not_null()); - } - if options.moderator_view.unwrap_or(false) { query = query.filter(community_moderator::person_id.is_not_null()); } @@ -445,12 +445,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, subscribed: CommunityFollower::to_subscribed_type(&a.5), - saved: a.6.is_some(), - read: a.7.is_some(), - creator_blocked: a.8.is_some(), + 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 3c2ce07fc..e47a71361 100644 --- a/crates/db_views_actor/src/comment_reply_view.rs +++ b/crates/db_views_actor/src/comment_reply_view.rs @@ -28,11 +28,10 @@ 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, @@ -48,10 +47,10 @@ type CommentReplyViewTuple = ( Community, Person, CommentAggregatesNotInComment, - Option, + bool, Option, - Option, - Option, + bool, + bool, Option, ); @@ -113,10 +112,10 @@ fn queries<'a>() -> Queries< community::all_columns, aliases::person1.fields(person::all_columns), CommentAggregatesNotInComment::as_select(), - community_person_ban::all_columns.nullable(), + community_person_ban::id.nullable().is_not_null(), community_follower::all_columns.nullable(), - comment_saved::all_columns.nullable(), - person_block::all_columns.nullable(), + comment_saved::id.nullable().is_not_null(), + person_block::id.nullable().is_not_null(), comment_like::score.nullable(), )) }; @@ -228,10 +227,10 @@ impl JoinView for CommentReplyView { community: a.4, recipient: a.5, counts, - creator_banned_from_community: a.7.is_some(), + creator_banned_from_community: a.7, subscribed: CommunityFollower::to_subscribed_type(&a.8), - saved: a.9.is_some(), - creator_blocked: a.10.is_some(), + 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 9ca5c218c..d306e7c23 100644 --- a/crates/db_views_actor/src/community_view.rs +++ b/crates/db_views_actor/src/community_view.rs @@ -16,7 +16,6 @@ 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, @@ -29,7 +28,7 @@ type CommunityViewTuple = ( Community, CommunityAggregates, Option, - Option, + bool, ); fn queries<'a>() -> Queries< @@ -62,7 +61,7 @@ fn queries<'a>() -> Queries< community::all_columns, community_aggregates::all_columns, community_follower::all_columns.nullable(), - community_block::all_columns.nullable(), + community_block::id.nullable().is_not_null(), ); let not_removed_or_deleted = community::removed @@ -218,7 +217,7 @@ impl JoinView for CommunityView { community: a.0, counts: a.1, subscribed: CommunityFollower::to_subscribed_type(&a.2), - blocked: a.3.is_some(), + 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 08dc9c092..3b629bd8d 100644 --- a/crates/db_views_actor/src/person_mention_view.rs +++ b/crates/db_views_actor/src/person_mention_view.rs @@ -29,10 +29,9 @@ 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, }, @@ -49,10 +48,10 @@ type PersonMentionViewTuple = ( Community, Person, CommentAggregatesNotInComment, - Option, + bool, Option, - Option, - Option, + bool, + bool, Option, ); @@ -109,10 +108,10 @@ fn queries<'a>() -> Queries< community::all_columns, aliases::person1.fields(person::all_columns), CommentAggregatesNotInComment::as_select(), - community_person_ban::all_columns.nullable(), + community_person_ban::id.nullable().is_not_null(), community_follower::all_columns.nullable(), - comment_saved::all_columns.nullable(), - person_block::all_columns.nullable(), + comment_saved::id.nullable().is_not_null(), + person_block::id.nullable().is_not_null(), comment_like::score.nullable(), ); @@ -245,10 +244,10 @@ impl JoinView for PersonMentionView { community: a.4, recipient: a.5, counts, - creator_banned_from_community: a.7.is_some(), + creator_banned_from_community: a.7, subscribed: CommunityFollower::to_subscribed_type(&a.8), - saved: a.9.is_some(), - creator_blocked: a.10.is_some(), + saved: a.9, + creator_blocked: a.10, my_vote: a.11, } }