lemmy/crates/db_schema/src/aggregates/structs.rs
dullbananas 8e2cbc9a0f
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 08:14:07 -05:00

172 lines
6 KiB
Rust

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};
use serde::{Deserialize, Serialize};
#[cfg(feature = "full")]
use ts_rs::TS;
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
#[cfg_attr(feature = "full", diesel(table_name = comment_aggregates))]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
#[cfg_attr(feature = "full", diesel(primary_key(comment_id)))]
#[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, Associations, Identifiable, TS))]
#[cfg_attr(feature = "full", diesel(table_name = community_aggregates))]
#[cfg_attr(
feature = "full",
diesel(belongs_to(crate::source::community::Community))
)]
#[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,
}
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
#[cfg_attr(feature = "full", diesel(table_name = person_aggregates))]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))]
#[cfg_attr(feature = "full", diesel(primary_key(person_id)))]
#[cfg_attr(feature = "full", ts(export))]
/// Aggregate data for a person.
pub struct PersonAggregates {
pub person_id: PersonId,
pub post_count: i64,
#[serde(skip)]
pub post_score: i64,
pub comment_count: i64,
#[serde(skip)]
pub comment_score: i64,
}
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
#[cfg_attr(feature = "full", diesel(table_name = post_aggregates))]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
#[cfg_attr(feature = "full", diesel(primary_key(post_id)))]
#[cfg_attr(feature = "full", ts(export))]
/// 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.
#[serde(skip)]
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, Associations, Identifiable))]
#[cfg_attr(feature = "full", diesel(table_name = person_post_aggregates))]
#[cfg_attr(feature = "full", diesel(primary_key(person_id, post_id)))]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))]
/// 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, Associations, Identifiable, TS))]
#[cfg_attr(feature = "full", diesel(table_name = site_aggregates))]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::site::Site)))]
#[cfg_attr(feature = "full", diesel(primary_key(site_id)))]
#[cfg_attr(feature = "full", ts(export))]
/// Aggregate data for a site.
pub struct SiteAggregates {
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,
}