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