Remove pointless block_views. (#4841)

- Fixes #4793
This commit is contained in:
Dessalines 2024-09-10 14:32:12 -04:00 committed by GitHub
parent 84794714da
commit d1866cbd04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 100 additions and 159 deletions

View File

@ -11,10 +11,12 @@ use lemmy_db_schema::{
RegistrationApplicationId,
},
source::{
community::Community,
federation_queue_state::FederationQueueState,
instance::Instance,
language::Language,
local_site_url_blocklist::LocalSiteUrlBlocklist,
person::Person,
tagline::Tagline,
},
ListingType,
@ -33,12 +35,9 @@ use lemmy_db_views::structs::{
SiteView,
};
use lemmy_db_views_actor::structs::{
CommunityBlockView,
CommunityFollowerView,
CommunityModeratorView,
CommunityView,
InstanceBlockView,
PersonBlockView,
PersonView,
};
use lemmy_db_views_moderator::structs::{
@ -337,9 +336,9 @@ pub struct MyUserInfo {
pub local_user_view: LocalUserView,
pub follows: Vec<CommunityFollowerView>,
pub moderates: Vec<CommunityModeratorView>,
pub community_blocks: Vec<CommunityBlockView>,
pub instance_blocks: Vec<InstanceBlockView>,
pub person_blocks: Vec<PersonBlockView>,
pub community_blocks: Vec<Community>,
pub instance_blocks: Vec<Instance>,
pub person_blocks: Vec<Person>,
pub discussion_languages: Vec<LanguageId>,
}

View File

@ -5,19 +5,15 @@ use lemmy_api_common::{
};
use lemmy_db_schema::source::{
actor_language::{LocalUserLanguage, SiteLanguage},
community_block::CommunityBlock,
instance_block::InstanceBlock,
language::Language,
local_site_url_blocklist::LocalSiteUrlBlocklist,
person_block::PersonBlock,
tagline::Tagline,
};
use lemmy_db_views::structs::{CustomEmojiView, LocalUserView, SiteView};
use lemmy_db_views_actor::structs::{
CommunityBlockView,
CommunityFollowerView,
CommunityModeratorView,
InstanceBlockView,
PersonBlockView,
PersonView,
};
use lemmy_db_views_actor::structs::{CommunityFollowerView, CommunityModeratorView, PersonView};
use lemmy_utils::{
error::{LemmyError, LemmyErrorExt, LemmyErrorType, LemmyResult},
CACHE_DURATION_API,
@ -81,9 +77,9 @@ pub async fn get_site(
discussion_languages,
) = lemmy_db_schema::try_join_with_pool!(pool => (
|pool| CommunityFollowerView::for_person(pool, person_id),
|pool| CommunityBlockView::for_person(pool, person_id),
|pool| InstanceBlockView::for_person(pool, person_id),
|pool| PersonBlockView::for_person(pool, person_id),
|pool| CommunityBlock::for_person(pool, person_id),
|pool| InstanceBlock::for_person(pool, person_id),
|pool| PersonBlock::for_person(pool, person_id),
|pool| CommunityModeratorView::for_person(pool, person_id, Some(&local_user_view.local_user)),
|pool| LocalUserLanguage::read(pool, local_user_id)
))

View File

@ -1,7 +1,10 @@
use crate::{
newtypes::{CommunityId, PersonId},
schema::community_block::dsl::{community_block, community_id, person_id},
source::community_block::{CommunityBlock, CommunityBlockForm},
schema::{community, community_block},
source::{
community::Community,
community_block::{CommunityBlock, CommunityBlockForm},
},
traits::Blockable,
utils::{get_conn, DbPool},
};
@ -9,6 +12,7 @@ use diesel::{
dsl::{exists, insert_into},
result::Error,
select,
ExpressionMethods,
QueryDsl,
};
use diesel_async::RunQueryDsl;
@ -21,11 +25,27 @@ impl CommunityBlock {
) -> Result<bool, Error> {
let conn = &mut get_conn(pool).await?;
select(exists(
community_block.find((for_person_id, for_community_id)),
community_block::table.find((for_person_id, for_community_id)),
))
.get_result(conn)
.await
}
pub async fn for_person(
pool: &mut DbPool<'_>,
person_id: PersonId,
) -> Result<Vec<Community>, Error> {
let conn = &mut get_conn(pool).await?;
community_block::table
.inner_join(community::table)
.select(community::all_columns)
.filter(community_block::person_id.eq(person_id))
.filter(community::deleted.eq(false))
.filter(community::removed.eq(false))
.order_by(community_block::published)
.load::<Community>(conn)
.await
}
}
#[async_trait]
@ -33,9 +53,9 @@ impl Blockable for CommunityBlock {
type Form = CommunityBlockForm;
async fn block(pool: &mut DbPool<'_>, community_block_form: &Self::Form) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(community_block)
insert_into(community_block::table)
.values(community_block_form)
.on_conflict((person_id, community_id))
.on_conflict((community_block::person_id, community_block::community_id))
.do_update()
.set(community_block_form)
.get_result::<Self>(conn)
@ -46,7 +66,7 @@ impl Blockable for CommunityBlock {
community_block_form: &Self::Form,
) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(community_block.find((
diesel::delete(community_block::table.find((
community_block_form.person_id,
community_block_form.community_id,
)))

View File

@ -1,7 +1,10 @@
use crate::{
newtypes::{InstanceId, PersonId},
schema::instance_block::dsl::{instance_block, instance_id, person_id},
source::instance_block::{InstanceBlock, InstanceBlockForm},
schema::{instance, instance_block},
source::{
instance::Instance,
instance_block::{InstanceBlock, InstanceBlockForm},
},
traits::Blockable,
utils::{get_conn, DbPool},
};
@ -9,6 +12,7 @@ use diesel::{
dsl::{exists, insert_into},
result::Error,
select,
ExpressionMethods,
QueryDsl,
};
use diesel_async::RunQueryDsl;
@ -21,11 +25,25 @@ impl InstanceBlock {
) -> Result<bool, Error> {
let conn = &mut get_conn(pool).await?;
select(exists(
instance_block.find((for_person_id, for_instance_id)),
instance_block::table.find((for_person_id, for_instance_id)),
))
.get_result(conn)
.await
}
pub async fn for_person(
pool: &mut DbPool<'_>,
person_id: PersonId,
) -> Result<Vec<Instance>, Error> {
let conn = &mut get_conn(pool).await?;
instance_block::table
.inner_join(instance::table)
.select(instance::all_columns)
.filter(instance_block::person_id.eq(person_id))
.order_by(instance_block::published)
.load::<Instance>(conn)
.await
}
}
#[async_trait]
@ -33,9 +51,9 @@ impl Blockable for InstanceBlock {
type Form = InstanceBlockForm;
async fn block(pool: &mut DbPool<'_>, instance_block_form: &Self::Form) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(instance_block)
insert_into(instance_block::table)
.values(instance_block_form)
.on_conflict((person_id, instance_id))
.on_conflict((instance_block::person_id, instance_block::instance_id))
.do_update()
.set(instance_block_form)
.get_result::<Self>(conn)
@ -46,7 +64,7 @@ impl Blockable for InstanceBlock {
instance_block_form: &Self::Form,
) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(instance_block.find((
diesel::delete(instance_block::table.find((
instance_block_form.person_id,
instance_block_form.instance_id,
)))

View File

@ -1,7 +1,10 @@
use crate::{
newtypes::PersonId,
schema::person_block::dsl::{person_block, person_id, target_id},
source::person_block::{PersonBlock, PersonBlockForm},
schema::{person, person_block},
source::{
person::Person,
person_block::{PersonBlock, PersonBlockForm},
},
traits::Blockable,
utils::{get_conn, DbPool},
};
@ -9,6 +12,8 @@ use diesel::{
dsl::{exists, insert_into},
result::Error,
select,
ExpressionMethods,
JoinOnDsl,
QueryDsl,
};
use diesel_async::RunQueryDsl;
@ -20,8 +25,30 @@ impl PersonBlock {
for_recipient_id: PersonId,
) -> Result<bool, Error> {
let conn = &mut get_conn(pool).await?;
select(exists(person_block.find((for_person_id, for_recipient_id))))
.get_result(conn)
select(exists(
person_block::table.find((for_person_id, for_recipient_id)),
))
.get_result(conn)
.await
}
pub async fn for_person(
pool: &mut DbPool<'_>,
person_id: PersonId,
) -> Result<Vec<Person>, Error> {
let conn = &mut get_conn(pool).await?;
let target_person_alias = diesel::alias!(person as person1);
person_block::table
.inner_join(person::table.on(person_block::person_id.eq(person::id)))
.inner_join(
target_person_alias.on(person_block::target_id.eq(target_person_alias.field(person::id))),
)
.select(target_person_alias.fields(person::all_columns))
.filter(person_block::person_id.eq(person_id))
.filter(target_person_alias.field(person::deleted).eq(false))
.order_by(person_block::published)
.load::<Person>(conn)
.await
}
}
@ -34,9 +61,9 @@ impl Blockable for PersonBlock {
person_block_form: &PersonBlockForm,
) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(person_block)
insert_into(person_block::table)
.values(person_block_form)
.on_conflict((person_id, target_id))
.on_conflict((person_block::person_id, person_block::target_id))
.do_update()
.set(person_block_form)
.get_result::<Self>(conn)
@ -44,8 +71,10 @@ impl Blockable for PersonBlock {
}
async fn unblock(pool: &mut DbPool<'_>, person_block_form: &Self::Form) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(person_block.find((person_block_form.person_id, person_block_form.target_id)))
.execute(conn)
.await
diesel::delete(
person_block::table.find((person_block_form.person_id, person_block_form.target_id)),
)
.execute(conn)
.await
}
}

View File

@ -1,24 +0,0 @@
use crate::structs::CommunityBlockView;
use diesel::{result::Error, ExpressionMethods, QueryDsl};
use diesel_async::RunQueryDsl;
use lemmy_db_schema::{
newtypes::PersonId,
schema::{community, community_block, person},
utils::{get_conn, DbPool},
};
impl CommunityBlockView {
pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
community_block::table
.inner_join(person::table)
.inner_join(community::table)
.select((person::all_columns, community::all_columns))
.filter(community_block::person_id.eq(person_id))
.filter(community::deleted.eq(false))
.filter(community::removed.eq(false))
.order_by(community_block::published)
.load::<CommunityBlockView>(conn)
.await
}
}

View File

@ -1,27 +0,0 @@
use crate::structs::InstanceBlockView;
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, NullableExpressionMethods, QueryDsl};
use diesel_async::RunQueryDsl;
use lemmy_db_schema::{
newtypes::PersonId,
schema::{instance, instance_block, person, site},
utils::{get_conn, DbPool},
};
impl InstanceBlockView {
pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
instance_block::table
.inner_join(person::table)
.inner_join(instance::table)
.left_join(site::table.on(site::instance_id.eq(instance::id)))
.select((
person::all_columns,
instance::all_columns,
site::all_columns.nullable(),
))
.filter(instance_block::person_id.eq(person_id))
.order_by(instance_block::published)
.load::<InstanceBlockView>(conn)
.await
}
}

View File

@ -1,8 +1,6 @@
#[cfg(feature = "full")]
pub mod comment_reply_view;
#[cfg(feature = "full")]
pub mod community_block_view;
#[cfg(feature = "full")]
pub mod community_follower_view;
#[cfg(feature = "full")]
pub mod community_moderator_view;
@ -11,10 +9,6 @@ pub mod community_person_ban_view;
#[cfg(feature = "full")]
pub mod community_view;
#[cfg(feature = "full")]
pub mod instance_block_view;
#[cfg(feature = "full")]
pub mod person_block_view;
#[cfg(feature = "full")]
pub mod person_mention_view;
#[cfg(feature = "full")]
pub mod person_view;

View File

@ -1,30 +0,0 @@
use crate::structs::PersonBlockView;
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, QueryDsl};
use diesel_async::RunQueryDsl;
use lemmy_db_schema::{
newtypes::PersonId,
schema::{person, person_block},
utils::{get_conn, DbPool},
};
impl PersonBlockView {
pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let target_person_alias = diesel::alias!(person as person1);
person_block::table
.inner_join(person::table.on(person_block::person_id.eq(person::id)))
.inner_join(
target_person_alias.on(person_block::target_id.eq(target_person_alias.field(person::id))),
)
.select((
person::all_columns,
target_person_alias.fields(person::all_columns),
))
.filter(person_block::person_id.eq(person_id))
.filter(target_person_alias.field(person::deleted).eq(false))
.order_by(person_block::published)
.load::<PersonBlockView>(conn)
.await
}
}

View File

@ -6,11 +6,9 @@ use lemmy_db_schema::{
comment::Comment,
comment_reply::CommentReply,
community::Community,
instance::Instance,
person::Person,
person_mention::PersonMention,
post::Post,
site::Site,
},
SubscribedType,
};
@ -19,28 +17,6 @@ use serde_with::skip_serializing_none;
#[cfg(feature = "full")]
use ts_rs::TS;
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
#[cfg_attr(feature = "full", ts(export))]
/// A community block.
pub struct CommunityBlockView {
pub person: Person,
pub community: Community,
}
#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
#[cfg_attr(feature = "full", ts(export))]
/// An instance block by a user.
pub struct InstanceBlockView {
pub person: Person,
pub instance: Instance,
pub site: Option<Site>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
@ -83,16 +59,6 @@ pub struct CommunityView {
pub banned_from_community: bool,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS, Queryable))]
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
#[cfg_attr(feature = "full", ts(export))]
/// A person block.
pub struct PersonBlockView {
pub person: Person,
pub target: Person,
}
#[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS, Queryable))]