1 use crate::newtypes::{CommentId, CommunityId, PersonId, PostId, SiteId};
2 #[cfg(feature = "full")]
7 person_post_aggregates,
11 use serde::{Deserialize, Serialize};
12 #[cfg(feature = "full")]
15 #[derive(PartialEq, Eq, 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 {
23 pub comment_id: CommentId,
27 pub published: chrono::NaiveDateTime,
28 /// The total number of children in this comment branch.
32 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
33 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
34 #[cfg_attr(feature = "full", diesel(table_name = community_aggregates))]
37 diesel(belongs_to(crate::source::community::Community))
39 #[cfg_attr(feature = "full", ts(export))]
40 /// Aggregate data for a community.
41 pub struct CommunityAggregates {
43 pub community_id: CommunityId,
47 pub published: chrono::NaiveDateTime,
48 /// The number of users with any activity in the last day.
49 pub users_active_day: i64,
50 /// The number of users with any activity in the last week.
51 pub users_active_week: i64,
52 /// The number of users with any activity in the last month.
53 pub users_active_month: i64,
54 /// The number of users with any activity in the last year.
55 pub users_active_half_year: i64,
58 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone, Default)]
59 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
60 #[cfg_attr(feature = "full", diesel(table_name = person_aggregates))]
61 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))]
62 #[cfg_attr(feature = "full", ts(export))]
63 /// Aggregate data for a person.
64 pub struct PersonAggregates {
66 pub person_id: PersonId,
69 pub comment_count: i64,
70 pub comment_score: i64,
73 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
74 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
75 #[cfg_attr(feature = "full", diesel(table_name = post_aggregates))]
76 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
77 #[cfg_attr(feature = "full", ts(export))]
78 /// Aggregate data for a post.
79 pub struct PostAggregates {
86 pub published: chrono::NaiveDateTime,
87 /// A newest comment time, limited to 2 days, to prevent necrobumping
88 pub newest_comment_time_necro: chrono::NaiveDateTime,
89 /// The time of the newest comment in the post.
90 pub newest_comment_time: chrono::NaiveDateTime,
91 /// If the post is featured on the community.
92 pub featured_community: bool,
93 /// If the post is featured on the site / to local.
94 pub featured_local: bool,
97 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
98 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
99 #[cfg_attr(feature = "full", diesel(table_name = person_post_aggregates))]
100 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))]
101 /// Aggregate data for a person's post.
102 pub struct PersonPostAggregates {
104 pub person_id: PersonId,
106 /// The number of comments they've read on that post.
108 /// This is updated to the current post comment count every time they view a post.
109 pub read_comments: i64,
110 pub published: chrono::NaiveDateTime,
113 #[derive(Clone, Default)]
114 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
115 #[cfg_attr(feature = "full", diesel(table_name = person_post_aggregates))]
116 pub struct PersonPostAggregatesForm {
117 pub person_id: PersonId,
119 pub read_comments: i64,
120 pub published: Option<chrono::NaiveDateTime>,
123 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
124 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
125 #[cfg_attr(feature = "full", diesel(table_name = site_aggregates))]
126 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::site::Site)))]
127 #[cfg_attr(feature = "full", ts(export))]
128 /// Aggregate data for a site.
129 pub struct SiteAggregates {
135 pub communities: i64,
136 /// The number of users with any activity in the last day.
137 pub users_active_day: i64,
138 /// The number of users with any activity in the last week.
139 pub users_active_week: i64,
140 /// The number of users with any activity in the last month.
141 pub users_active_month: i64,
142 /// The number of users with any activity in the last half year.
143 pub users_active_half_year: i64,