]> Untitled Git - lemmy.git/blob - crates/db_schema/src/aggregates/structs.rs
Showing # of unread comments for posts. Fixes #2134 (#2393)
[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   person_post_aggregates,
10   post_aggregates,
11   site_aggregates,
12 };
13
14 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
15 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
16 #[cfg_attr(feature = "full", diesel(table_name = comment_aggregates))]
17 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
18 pub struct CommentAggregates {
19   pub id: i32,
20   pub comment_id: CommentId,
21   pub score: i64,
22   pub upvotes: i64,
23   pub downvotes: i64,
24   pub published: chrono::NaiveDateTime,
25   pub child_count: i32,
26 }
27
28 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
29 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
30 #[cfg_attr(feature = "full", diesel(table_name = community_aggregates))]
31 #[cfg_attr(
32   feature = "full",
33   diesel(belongs_to(crate::source::community::Community))
34 )]
35 pub struct CommunityAggregates {
36   pub id: i32,
37   pub community_id: CommunityId,
38   pub subscribers: i64,
39   pub posts: i64,
40   pub comments: i64,
41   pub published: chrono::NaiveDateTime,
42   pub users_active_day: i64,
43   pub users_active_week: i64,
44   pub users_active_month: i64,
45   pub users_active_half_year: i64,
46 }
47
48 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone, Default)]
49 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
50 #[cfg_attr(feature = "full", diesel(table_name = person_aggregates))]
51 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))]
52 pub struct PersonAggregates {
53   pub id: i32,
54   pub person_id: PersonId,
55   pub post_count: i64,
56   pub post_score: i64,
57   pub comment_count: i64,
58   pub comment_score: i64,
59 }
60
61 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
62 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
63 #[cfg_attr(feature = "full", diesel(table_name = post_aggregates))]
64 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
65 pub struct PostAggregates {
66   pub id: i32,
67   pub post_id: PostId,
68   pub comments: i64,
69   pub score: i64,
70   pub upvotes: i64,
71   pub downvotes: i64,
72   pub stickied: bool,
73   pub published: chrono::NaiveDateTime,
74   pub newest_comment_time_necro: chrono::NaiveDateTime, // A newest comment time, limited to 2 days, to prevent necrobumping
75   pub newest_comment_time: chrono::NaiveDateTime,
76 }
77
78 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
79 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
80 #[cfg_attr(feature = "full", diesel(table_name = person_post_aggregates))]
81 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))]
82 pub struct PersonPostAggregates {
83   pub id: i32,
84   pub person_id: PersonId,
85   pub post_id: PostId,
86   pub read_comments: i64,
87   pub published: chrono::NaiveDateTime,
88 }
89
90 #[derive(Clone, Default)]
91 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
92 #[cfg_attr(feature = "full", diesel(table_name = person_post_aggregates))]
93 pub struct PersonPostAggregatesForm {
94   pub person_id: PersonId,
95   pub post_id: PostId,
96   pub read_comments: i64,
97   pub published: Option<chrono::NaiveDateTime>,
98 }
99
100 #[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
101 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
102 #[cfg_attr(feature = "full", diesel(table_name = site_aggregates))]
103 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::site::Site)))]
104 pub struct SiteAggregates {
105   pub id: i32,
106   pub site_id: i32,
107   pub users: i64,
108   pub posts: i64,
109   pub comments: i64,
110   pub communities: i64,
111   pub users_active_day: i64,
112   pub users_active_week: i64,
113   pub users_active_month: i64,
114   pub users_active_half_year: i64,
115 }