lemmy/crates/db_schema/src/aggregates/structs.rs

205 lines
6.6 KiB
Rust
Raw Normal View History

use crate::newtypes::{CommentId, CommunityId, InstanceId, PersonId, PostId, SiteId};
#[cfg(feature = "full")]
use crate::schema::{
comment_aggregates,
community_aggregates,
person_aggregates,
person_post_aggregates,
post_aggregates,
site_aggregates,
};
use chrono::{DateTime, Utc};
#[cfg(feature = "full")]
use i_love_jesus::CursorKeysModule;
use serde::{Deserialize, Serialize};
#[cfg(feature = "full")]
use ts_rs::TS;
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(
feature = "full",
derive(Queryable, Selectable, Associations, Identifiable, TS)
)]
#[cfg_attr(feature = "full", diesel(table_name = comment_aggregates))]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
Remove id column and use different primary key on some tables (#4093) * post_saved * fmt * remove unique and not null * put person_id first in primary key and remove index * use post_saved.find * change captcha_answer * remove removal of not null * comment_aggregates * comment_like * comment_saved * aggregates * remove "\" * deduplicate site_aggregates * person_post_aggregates * community_moderator * community_block * community_person_ban * custom_emoji_keyword * federation allow/block list * federation_queue_state * instance_block * local_site_rate_limit, local_user_language, login_token * person_ban, person_block, person_follower, post_like, post_read, received_activity * community_follower, community_language, site_language * fmt * image_upload * remove unused newtypes * remove more indexes * use .find * merge * fix site_aggregates_site function * fmt * Primary keys dess (#17) * Also order reports by oldest first (ref #4123) (#4129) * Support signed fetch for federation (fixes #868) (#4125) * Support signed fetch for federation (fixes #868) * taplo * add federation queue state to get_federated_instances api (#4104) * add federation queue state to get_federated_instances api * feature gate * move retry sleep function * move stuff around * Add UI setting for collapsing bot comments. Fixes #3838 (#4098) * Add UI setting for collapsing bot comments. Fixes #3838 * Fixing clippy check. * Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131) * Only check auth secure on release mode. (#4127) * Only check auth secure on release mode. * Fixing wrong js-client. * Adding is_debug_mode var. * Fixing the desktop image on the README. (#4135) * Delete dupes and add possibly missing unique constraint on person_aggregates. * Fixing clippy lints. --------- Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com> * fmt * Update community_block.rs * Update instance_block.rs * Update person_block.rs * Update person_block.rs --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
#[cfg_attr(feature = "full", diesel(primary_key(comment_id)))]
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
#[cfg_attr(feature = "full", ts(export))]
/// Aggregate data for a comment.
pub struct CommentAggregates {
pub comment_id: CommentId,
pub score: i64,
pub upvotes: i64,
pub downvotes: i64,
pub published: DateTime<Utc>,
/// The total number of children in this comment branch.
pub child_count: i32,
#[serde(skip)]
pub hot_rank: f64,
#[serde(skip)]
pub controversy_rank: f64,
}
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(
feature = "full",
derive(Queryable, Selectable, Associations, Identifiable, TS)
)]
#[cfg_attr(feature = "full", diesel(table_name = community_aggregates))]
#[cfg_attr(
feature = "full",
diesel(belongs_to(crate::source::community::Community))
)]
Remove id column and use different primary key on some tables (#4093) * post_saved * fmt * remove unique and not null * put person_id first in primary key and remove index * use post_saved.find * change captcha_answer * remove removal of not null * comment_aggregates * comment_like * comment_saved * aggregates * remove "\" * deduplicate site_aggregates * person_post_aggregates * community_moderator * community_block * community_person_ban * custom_emoji_keyword * federation allow/block list * federation_queue_state * instance_block * local_site_rate_limit, local_user_language, login_token * person_ban, person_block, person_follower, post_like, post_read, received_activity * community_follower, community_language, site_language * fmt * image_upload * remove unused newtypes * remove more indexes * use .find * merge * fix site_aggregates_site function * fmt * Primary keys dess (#17) * Also order reports by oldest first (ref #4123) (#4129) * Support signed fetch for federation (fixes #868) (#4125) * Support signed fetch for federation (fixes #868) * taplo * add federation queue state to get_federated_instances api (#4104) * add federation queue state to get_federated_instances api * feature gate * move retry sleep function * move stuff around * Add UI setting for collapsing bot comments. Fixes #3838 (#4098) * Add UI setting for collapsing bot comments. Fixes #3838 * Fixing clippy check. * Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131) * Only check auth secure on release mode. (#4127) * Only check auth secure on release mode. * Fixing wrong js-client. * Adding is_debug_mode var. * Fixing the desktop image on the README. (#4135) * Delete dupes and add possibly missing unique constraint on person_aggregates. * Fixing clippy lints. --------- Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com> * fmt * Update community_block.rs * Update instance_block.rs * Update person_block.rs * Update person_block.rs --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
#[cfg_attr(feature = "full", diesel(primary_key(community_id)))]
#[cfg_attr(feature = "full", ts(export))]
/// Aggregate data for a community.
pub struct CommunityAggregates {
pub community_id: CommunityId,
pub subscribers: i64,
pub posts: i64,
pub comments: i64,
pub published: DateTime<Utc>,
/// The number of users with any activity in the last day.
pub users_active_day: i64,
/// The number of users with any activity in the last week.
pub users_active_week: i64,
/// The number of users with any activity in the last month.
pub users_active_month: i64,
/// The number of users with any activity in the last year.
pub users_active_half_year: i64,
#[serde(skip)]
pub hot_rank: f64,
pub subscribers_local: i64,
}
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(
feature = "full",
derive(Queryable, Selectable, Associations, Identifiable, TS)
)]
#[cfg_attr(feature = "full", diesel(table_name = person_aggregates))]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))]
Remove id column and use different primary key on some tables (#4093) * post_saved * fmt * remove unique and not null * put person_id first in primary key and remove index * use post_saved.find * change captcha_answer * remove removal of not null * comment_aggregates * comment_like * comment_saved * aggregates * remove "\" * deduplicate site_aggregates * person_post_aggregates * community_moderator * community_block * community_person_ban * custom_emoji_keyword * federation allow/block list * federation_queue_state * instance_block * local_site_rate_limit, local_user_language, login_token * person_ban, person_block, person_follower, post_like, post_read, received_activity * community_follower, community_language, site_language * fmt * image_upload * remove unused newtypes * remove more indexes * use .find * merge * fix site_aggregates_site function * fmt * Primary keys dess (#17) * Also order reports by oldest first (ref #4123) (#4129) * Support signed fetch for federation (fixes #868) (#4125) * Support signed fetch for federation (fixes #868) * taplo * add federation queue state to get_federated_instances api (#4104) * add federation queue state to get_federated_instances api * feature gate * move retry sleep function * move stuff around * Add UI setting for collapsing bot comments. Fixes #3838 (#4098) * Add UI setting for collapsing bot comments. Fixes #3838 * Fixing clippy check. * Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131) * Only check auth secure on release mode. (#4127) * Only check auth secure on release mode. * Fixing wrong js-client. * Adding is_debug_mode var. * Fixing the desktop image on the README. (#4135) * Delete dupes and add possibly missing unique constraint on person_aggregates. * Fixing clippy lints. --------- Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com> * fmt * Update community_block.rs * Update instance_block.rs * Update person_block.rs * Update person_block.rs --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
#[cfg_attr(feature = "full", diesel(primary_key(person_id)))]
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
#[cfg_attr(feature = "full", ts(export))]
/// Aggregate data for a person.
pub struct PersonAggregates {
pub person_id: PersonId,
pub post_count: i64,
2023-10-24 21:26:09 +00:00
#[serde(skip)]
pub post_score: i64,
pub comment_count: i64,
2023-10-24 21:26:09 +00:00
#[serde(skip)]
pub comment_score: i64,
}
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(
feature = "full",
derive(
Queryable,
Selectable,
Associations,
Identifiable,
TS,
CursorKeysModule
)
)]
#[cfg_attr(feature = "full", diesel(table_name = post_aggregates))]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
Remove id column and use different primary key on some tables (#4093) * post_saved * fmt * remove unique and not null * put person_id first in primary key and remove index * use post_saved.find * change captcha_answer * remove removal of not null * comment_aggregates * comment_like * comment_saved * aggregates * remove "\" * deduplicate site_aggregates * person_post_aggregates * community_moderator * community_block * community_person_ban * custom_emoji_keyword * federation allow/block list * federation_queue_state * instance_block * local_site_rate_limit, local_user_language, login_token * person_ban, person_block, person_follower, post_like, post_read, received_activity * community_follower, community_language, site_language * fmt * image_upload * remove unused newtypes * remove more indexes * use .find * merge * fix site_aggregates_site function * fmt * Primary keys dess (#17) * Also order reports by oldest first (ref #4123) (#4129) * Support signed fetch for federation (fixes #868) (#4125) * Support signed fetch for federation (fixes #868) * taplo * add federation queue state to get_federated_instances api (#4104) * add federation queue state to get_federated_instances api * feature gate * move retry sleep function * move stuff around * Add UI setting for collapsing bot comments. Fixes #3838 (#4098) * Add UI setting for collapsing bot comments. Fixes #3838 * Fixing clippy check. * Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131) * Only check auth secure on release mode. (#4127) * Only check auth secure on release mode. * Fixing wrong js-client. * Adding is_debug_mode var. * Fixing the desktop image on the README. (#4135) * Delete dupes and add possibly missing unique constraint on person_aggregates. * Fixing clippy lints. --------- Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com> * fmt * Update community_block.rs * Update instance_block.rs * Update person_block.rs * Update person_block.rs --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
#[cfg_attr(feature = "full", diesel(primary_key(post_id)))]
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
#[cfg_attr(feature = "full", ts(export))]
#[cfg_attr(feature = "full", cursor_keys_module(name = post_aggregates_keys))]
/// Aggregate data for a post.
pub struct PostAggregates {
pub post_id: PostId,
pub comments: i64,
pub score: i64,
pub upvotes: i64,
pub downvotes: i64,
pub published: DateTime<Utc>,
#[serde(skip)]
/// A newest comment time, limited to 2 days, to prevent necrobumping
pub newest_comment_time_necro: DateTime<Utc>,
/// The time of the newest comment in the post.
pub newest_comment_time: DateTime<Utc>,
/// If the post is featured on the community.
#[serde(skip)]
pub featured_community: bool,
/// If the post is featured on the site / to local.
#[serde(skip)]
pub featured_local: bool,
#[serde(skip)]
pub hot_rank: f64,
#[serde(skip)]
pub hot_rank_active: f64,
#[serde(skip)]
pub community_id: CommunityId,
#[serde(skip)]
pub creator_id: PersonId,
#[serde(skip)]
pub controversy_rank: f64,
#[serde(skip)]
pub instance_id: InstanceId,
/// A rank that amplifies smaller communities
#[serde(skip)]
pub scaled_rank: f64,
}
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(
feature = "full",
derive(Queryable, Selectable, Associations, Identifiable)
)]
#[cfg_attr(feature = "full", diesel(table_name = person_post_aggregates))]
Remove id column and use different primary key on some tables (#4093) * post_saved * fmt * remove unique and not null * put person_id first in primary key and remove index * use post_saved.find * change captcha_answer * remove removal of not null * comment_aggregates * comment_like * comment_saved * aggregates * remove "\" * deduplicate site_aggregates * person_post_aggregates * community_moderator * community_block * community_person_ban * custom_emoji_keyword * federation allow/block list * federation_queue_state * instance_block * local_site_rate_limit, local_user_language, login_token * person_ban, person_block, person_follower, post_like, post_read, received_activity * community_follower, community_language, site_language * fmt * image_upload * remove unused newtypes * remove more indexes * use .find * merge * fix site_aggregates_site function * fmt * Primary keys dess (#17) * Also order reports by oldest first (ref #4123) (#4129) * Support signed fetch for federation (fixes #868) (#4125) * Support signed fetch for federation (fixes #868) * taplo * add federation queue state to get_federated_instances api (#4104) * add federation queue state to get_federated_instances api * feature gate * move retry sleep function * move stuff around * Add UI setting for collapsing bot comments. Fixes #3838 (#4098) * Add UI setting for collapsing bot comments. Fixes #3838 * Fixing clippy check. * Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131) * Only check auth secure on release mode. (#4127) * Only check auth secure on release mode. * Fixing wrong js-client. * Adding is_debug_mode var. * Fixing the desktop image on the README. (#4135) * Delete dupes and add possibly missing unique constraint on person_aggregates. * Fixing clippy lints. --------- Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com> * fmt * Update community_block.rs * Update instance_block.rs * Update person_block.rs * Update person_block.rs --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
#[cfg_attr(feature = "full", diesel(primary_key(person_id, post_id)))]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))]
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
/// Aggregate data for a person's post.
pub struct PersonPostAggregates {
pub person_id: PersonId,
pub post_id: PostId,
/// The number of comments they've read on that post.
///
/// This is updated to the current post comment count every time they view a post.
pub read_comments: i64,
pub published: DateTime<Utc>,
}
#[derive(Clone, Default)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", diesel(table_name = person_post_aggregates))]
pub struct PersonPostAggregatesForm {
pub person_id: PersonId,
pub post_id: PostId,
pub read_comments: i64,
pub published: Option<DateTime<Utc>>,
}
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(
feature = "full",
derive(Queryable, Selectable, Associations, Identifiable, TS)
)]
#[cfg_attr(feature = "full", diesel(table_name = site_aggregates))]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::site::Site)))]
Remove id column and use different primary key on some tables (#4093) * post_saved * fmt * remove unique and not null * put person_id first in primary key and remove index * use post_saved.find * change captcha_answer * remove removal of not null * comment_aggregates * comment_like * comment_saved * aggregates * remove "\" * deduplicate site_aggregates * person_post_aggregates * community_moderator * community_block * community_person_ban * custom_emoji_keyword * federation allow/block list * federation_queue_state * instance_block * local_site_rate_limit, local_user_language, login_token * person_ban, person_block, person_follower, post_like, post_read, received_activity * community_follower, community_language, site_language * fmt * image_upload * remove unused newtypes * remove more indexes * use .find * merge * fix site_aggregates_site function * fmt * Primary keys dess (#17) * Also order reports by oldest first (ref #4123) (#4129) * Support signed fetch for federation (fixes #868) (#4125) * Support signed fetch for federation (fixes #868) * taplo * add federation queue state to get_federated_instances api (#4104) * add federation queue state to get_federated_instances api * feature gate * move retry sleep function * move stuff around * Add UI setting for collapsing bot comments. Fixes #3838 (#4098) * Add UI setting for collapsing bot comments. Fixes #3838 * Fixing clippy check. * Only keep sent and received activities for 7 days (fixes #4113, fixes #4110) (#4131) * Only check auth secure on release mode. (#4127) * Only check auth secure on release mode. * Fixing wrong js-client. * Adding is_debug_mode var. * Fixing the desktop image on the README. (#4135) * Delete dupes and add possibly missing unique constraint on person_aggregates. * Fixing clippy lints. --------- Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com> * fmt * Update community_block.rs * Update instance_block.rs * Update person_block.rs * Update person_block.rs --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: Nutomic <me@nutomic.com> Co-authored-by: phiresky <phireskyde+git@gmail.com>
2023-11-13 13:14:07 +00:00
#[cfg_attr(feature = "full", diesel(primary_key(site_id)))]
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))]
#[cfg_attr(feature = "full", ts(export))]
/// Aggregate data for a site.
pub struct SiteAggregates {
2022-11-09 10:05:00 +00:00
pub site_id: SiteId,
pub users: i64,
pub posts: i64,
pub comments: i64,
pub communities: i64,
/// The number of users with any activity in the last day.
pub users_active_day: i64,
/// The number of users with any activity in the last week.
pub users_active_week: i64,
/// The number of users with any activity in the last month.
pub users_active_month: i64,
/// The number of users with any activity in the last half year.
pub users_active_half_year: i64,
}