]> Untitled Git - lemmy.git/blob - crates/db_schema/src/aggregates/structs.rs
add enable_federated_downvotes site option
[lemmy.git] / crates / db_schema / src / aggregates / structs.rs
1 use crate::newtypes::{CommentId, CommunityId, PersonId, PostId, SiteId};
2 #[cfg(feature = "full")]
3 use crate::schema::{
4   comment_aggregates,
5   community_aggregates,
6   person_aggregates,
7   person_post_aggregates,
8   post_aggregates,
9   site_aggregates,
10 };
11 use serde::{Deserialize, Serialize};
12 #[cfg(feature = "full")]
13 use ts_rs::TS;
14
15 #[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
16 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
17 #[cfg_attr(feature = "full", diesel(table_name = comment_aggregates))]
18 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
19 #[cfg_attr(feature = "full", ts(export))]
20 /// Aggregate data for a comment.
21 pub struct CommentAggregates {
22   pub id: i32,
23   pub comment_id: CommentId,
24   pub score: i64,
25   pub upvotes: i64,
26   pub downvotes: i64,
27   pub published: chrono::NaiveDateTime,
28   /// The total number of children in this comment branch.
29   pub child_count: i32,
30   pub hot_rank: i32,
31   pub controversy_rank: f64,
32 }
33
34 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
35 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
36 #[cfg_attr(feature = "full", diesel(table_name = community_aggregates))]
37 #[cfg_attr(
38   feature = "full",
39   diesel(belongs_to(crate::source::community::Community))
40 )]
41 #[cfg_attr(feature = "full", ts(export))]
42 /// Aggregate data for a community.
43 pub struct CommunityAggregates {
44   pub id: i32,
45   pub community_id: CommunityId,
46   pub subscribers: i64,
47   pub posts: i64,
48   pub comments: i64,
49   pub published: chrono::NaiveDateTime,
50   /// The number of users with any activity in the last day.
51   pub users_active_day: i64,
52   /// The number of users with any activity in the last week.
53   pub users_active_week: i64,
54   /// The number of users with any activity in the last month.
55   pub users_active_month: i64,
56   /// The number of users with any activity in the last year.
57   pub users_active_half_year: i64,
58   pub hot_rank: i32,
59 }
60
61 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone, Default)]
62 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
63 #[cfg_attr(feature = "full", diesel(table_name = person_aggregates))]
64 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))]
65 #[cfg_attr(feature = "full", ts(export))]
66 /// Aggregate data for a person.
67 pub struct PersonAggregates {
68   pub id: i32,
69   pub person_id: PersonId,
70   pub post_count: i64,
71   pub post_score: i64,
72   pub comment_count: i64,
73   pub comment_score: i64,
74 }
75
76 #[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
77 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
78 #[cfg_attr(feature = "full", diesel(table_name = post_aggregates))]
79 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
80 #[cfg_attr(feature = "full", ts(export))]
81 /// Aggregate data for a post.
82 pub struct PostAggregates {
83   pub id: i32,
84   pub post_id: PostId,
85   pub comments: i64,
86   pub score: i64,
87   pub upvotes: i64,
88   pub downvotes: i64,
89   pub published: chrono::NaiveDateTime,
90   /// A newest comment time, limited to 2 days, to prevent necrobumping  
91   pub newest_comment_time_necro: chrono::NaiveDateTime,
92   /// The time of the newest comment in the post.
93   pub newest_comment_time: chrono::NaiveDateTime,
94   /// If the post is featured on the community.
95   pub featured_community: bool,
96   /// If the post is featured on the site / to local.
97   pub featured_local: bool,
98   pub hot_rank: i32,
99   pub hot_rank_active: i32,
100   pub community_id: CommunityId,
101   pub creator_id: PersonId,
102   pub controversy_rank: f64,
103 }
104
105 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
106 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
107 #[cfg_attr(feature = "full", diesel(table_name = person_post_aggregates))]
108 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))]
109 /// Aggregate data for a person's post.
110 pub struct PersonPostAggregates {
111   pub id: i32,
112   pub person_id: PersonId,
113   pub post_id: PostId,
114   /// The number of comments they've read on that post.
115   ///
116   /// This is updated to the current post comment count every time they view a post.
117   pub read_comments: i64,
118   pub published: chrono::NaiveDateTime,
119 }
120
121 #[derive(Clone, Default)]
122 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
123 #[cfg_attr(feature = "full", diesel(table_name = person_post_aggregates))]
124 pub struct PersonPostAggregatesForm {
125   pub person_id: PersonId,
126   pub post_id: PostId,
127   pub read_comments: i64,
128   pub published: Option<chrono::NaiveDateTime>,
129 }
130
131 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
132 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
133 #[cfg_attr(feature = "full", diesel(table_name = site_aggregates))]
134 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::site::Site)))]
135 #[cfg_attr(feature = "full", ts(export))]
136 /// Aggregate data for a site.
137 pub struct SiteAggregates {
138   pub id: i32,
139   pub site_id: SiteId,
140   pub users: i64,
141   pub posts: i64,
142   pub comments: i64,
143   pub communities: i64,
144   /// The number of users with any activity in the last day.
145   pub users_active_day: i64,
146   /// The number of users with any activity in the last week.
147   pub users_active_week: i64,
148   /// The number of users with any activity in the last month.
149   pub users_active_month: i64,
150   /// The number of users with any activity in the last half year.
151   pub users_active_half_year: i64,
152 }