]> Untitled Git - lemmy.git/blob - crates/db_schema/src/aggregates/structs.rs
First pass at adding comment trees. (#2362)
[lemmy.git] / crates / db_schema / src / aggregates / structs.rs
1 use crate::newtypes::{CommentId, CommunityId, PersonId, PostId};
2 use serde::{Deserialize, Serialize};
3
4 #[cfg(feature = "full")]
5 use crate::schema::{
6   comment_aggregates,
7   community_aggregates,
8   person_aggregates,
9   post_aggregates,
10   site_aggregates,
11 };
12
13 #[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
14 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
15 #[cfg_attr(feature = "full", table_name = "comment_aggregates")]
16 pub struct CommentAggregates {
17   pub id: i32,
18   pub comment_id: CommentId,
19   pub score: i64,
20   pub upvotes: i64,
21   pub downvotes: i64,
22   pub published: chrono::NaiveDateTime,
23   pub child_count: i32,
24 }
25
26 #[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
27 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
28 #[cfg_attr(feature = "full", table_name = "community_aggregates")]
29 pub struct CommunityAggregates {
30   pub id: i32,
31   pub community_id: CommunityId,
32   pub subscribers: i64,
33   pub posts: i64,
34   pub comments: i64,
35   pub published: chrono::NaiveDateTime,
36   pub users_active_day: i64,
37   pub users_active_week: i64,
38   pub users_active_month: i64,
39   pub users_active_half_year: i64,
40 }
41
42 #[derive(PartialEq, Debug, Serialize, Deserialize, Clone, Default)]
43 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
44 #[cfg_attr(feature = "full", table_name = "person_aggregates")]
45 pub struct PersonAggregates {
46   pub id: i32,
47   pub person_id: PersonId,
48   pub post_count: i64,
49   pub post_score: i64,
50   pub comment_count: i64,
51   pub comment_score: i64,
52 }
53
54 #[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
55 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
56 #[cfg_attr(feature = "full", table_name = "post_aggregates")]
57 pub struct PostAggregates {
58   pub id: i32,
59   pub post_id: PostId,
60   pub comments: i64,
61   pub score: i64,
62   pub upvotes: i64,
63   pub downvotes: i64,
64   pub stickied: bool,
65   pub published: chrono::NaiveDateTime,
66   pub newest_comment_time_necro: chrono::NaiveDateTime, // A newest comment time, limited to 2 days, to prevent necrobumping
67   pub newest_comment_time: chrono::NaiveDateTime,
68 }
69
70 #[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
71 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
72 #[cfg_attr(feature = "full", table_name = "site_aggregates")]
73 pub struct SiteAggregates {
74   pub id: i32,
75   pub site_id: i32,
76   pub users: i64,
77   pub posts: i64,
78   pub comments: i64,
79   pub communities: i64,
80   pub users_active_day: i64,
81   pub users_active_week: i64,
82   pub users_active_month: i64,
83   pub users_active_half_year: i64,
84 }