community_block,
community_follower,
community_person_ban,
- language,
local_user_language,
person,
person_block,
+ person_post_aggregates,
post,
post_aggregates,
post_like,
},
source::{
community::{Community, CommunityFollower, CommunityPersonBan, CommunitySafe},
- language::Language,
local_user::LocalUser,
person::{Person, PersonSafe},
person_block::PersonBlock,
Option<PostRead>,
Option<PersonBlock>,
Option<i16>,
- Language,
+ i64,
);
+sql_function!(fn coalesce(x: sql_types::Nullable<sql_types::BigInt>, y: sql_types::BigInt) -> sql_types::BigInt);
+
impl PostView {
pub fn read(
conn: &mut PgConnection,
read,
creator_blocked,
post_like,
- language,
+ unread_comments,
) = post::table
.find(post_id)
.inner_join(person::table)
.and(post_like::person_id.eq(person_id_join)),
),
)
- .inner_join(language::table)
+ .left_join(
+ person_post_aggregates::table.on(
+ post::id
+ .eq(person_post_aggregates::post_id)
+ .and(person_post_aggregates::person_id.eq(person_id_join)),
+ ),
+ )
.select((
post::all_columns,
Person::safe_columns_tuple(),
post_read::all_columns.nullable(),
person_block::all_columns.nullable(),
post_like::score.nullable(),
- language::all_columns,
+ coalesce(
+ post_aggregates::comments.nullable() - person_post_aggregates::read_comments.nullable(),
+ post_aggregates::comments,
+ ),
))
.first::<PostViewTuple>(conn)?;
read: read.is_some(),
creator_blocked: creator_blocked.is_some(),
my_vote,
- language,
+ unread_comments,
})
}
}
.and(post_like::person_id.eq(person_id_join)),
),
)
- .inner_join(language::table)
+ .left_join(
+ person_post_aggregates::table.on(
+ post::id
+ .eq(person_post_aggregates::post_id)
+ .and(person_post_aggregates::person_id.eq(person_id_join)),
+ ),
+ )
.left_join(
local_user_language::table.on(
post::language_id
post_read::all_columns.nullable(),
person_block::all_columns.nullable(),
post_like::score.nullable(),
- language::all_columns,
+ coalesce(
+ post_aggregates::comments.nullable() - person_post_aggregates::read_comments.nullable(),
+ post_aggregates::comments,
+ ),
))
.into_boxed();
read: a.7.is_some(),
creator_blocked: a.8.is_some(),
my_vote: a.9,
- language: a.10,
+ unread_comments: a.10,
})
.collect::<Vec<Self>>()
}
aggregates::structs::PostAggregates,
newtypes::LanguageId,
source::{
+ actor_language::LocalUserLanguage,
community::*,
community_block::{CommunityBlock, CommunityBlockForm},
language::Language,
local_user::{LocalUser, LocalUserForm},
- local_user_language::LocalUserLanguage,
person::*,
person_block::{PersonBlock, PersonBlockForm},
post::*,
assert_eq!(3, post_listings_all.len());
let french_id = Language::read_id_from_code(conn, "fr").unwrap();
- LocalUserLanguage::update_user_languages(
- conn,
- Some(vec![french_id]),
- data.inserted_local_user.id,
- )
- .unwrap();
+ LocalUserLanguage::update(conn, vec![french_id], data.inserted_local_user.id).unwrap();
let post_listing_french = PostQuery::builder()
.conn(conn)
assert_eq!(french_id, post_listing_french[0].post.language_id);
let undetermined_id = Language::read_id_from_code(conn, "und").unwrap();
- LocalUserLanguage::update_user_languages(
+ LocalUserLanguage::update(
conn,
- Some(vec![french_id, undetermined_id]),
+ vec![french_id, undetermined_id],
data.inserted_local_user.id,
)
.unwrap();
language_id: LanguageId(47),
},
my_vote: None,
+ unread_comments: 0,
creator: PersonSafe {
id: inserted_person.id,
name: inserted_person.name.clone(),
read: false,
saved: false,
creator_blocked: false,
- language: Language {
- id: LanguageId(47),
- code: "fr".to_string(),
- name: "Français".to_string(),
- },
}
}
}