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.
33 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
34 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
35 #[cfg_attr(feature = "full", diesel(table_name = community_aggregates))]
38 diesel(belongs_to(crate::source::community::Community))
40 #[cfg_attr(feature = "full", ts(export))]
41 /// Aggregate data for a community.
42 pub struct CommunityAggregates {
44 pub community_id: CommunityId,
48 pub published: chrono::NaiveDateTime,
49 /// The number of users with any activity in the last day.
50 pub users_active_day: i64,
51 /// The number of users with any activity in the last week.
52 pub users_active_week: i64,
53 /// The number of users with any activity in the last month.
54 pub users_active_month: i64,
55 /// The number of users with any activity in the last year.
56 pub users_active_half_year: i64,
60 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone, Default)]
61 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
62 #[cfg_attr(feature = "full", diesel(table_name = person_aggregates))]
63 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))]
64 #[cfg_attr(feature = "full", ts(export))]
65 /// Aggregate data for a person.
66 pub struct PersonAggregates {
68 pub person_id: PersonId,
71 pub comment_count: i64,
72 pub comment_score: i64,
75 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
76 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
77 #[cfg_attr(feature = "full", diesel(table_name = post_aggregates))]
78 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
79 #[cfg_attr(feature = "full", ts(export))]
80 /// Aggregate data for a post.
81 pub struct PostAggregates {
88 pub published: chrono::NaiveDateTime,
89 /// A newest comment time, limited to 2 days, to prevent necrobumping
90 pub newest_comment_time_necro: chrono::NaiveDateTime,
91 /// The time of the newest comment in the post.
92 pub newest_comment_time: chrono::NaiveDateTime,
93 /// If the post is featured on the community.
94 pub featured_community: bool,
95 /// If the post is featured on the site / to local.
96 pub featured_local: bool,
98 pub hot_rank_active: i32,
101 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
102 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
103 #[cfg_attr(feature = "full", diesel(table_name = person_post_aggregates))]
104 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))]
105 /// Aggregate data for a person's post.
106 pub struct PersonPostAggregates {
108 pub person_id: PersonId,
110 /// The number of comments they've read on that post.
112 /// This is updated to the current post comment count every time they view a post.
113 pub read_comments: i64,
114 pub published: chrono::NaiveDateTime,
117 #[derive(Clone, Default)]
118 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
119 #[cfg_attr(feature = "full", diesel(table_name = person_post_aggregates))]
120 pub struct PersonPostAggregatesForm {
121 pub person_id: PersonId,
123 pub read_comments: i64,
124 pub published: Option<chrono::NaiveDateTime>,
127 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
128 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
129 #[cfg_attr(feature = "full", diesel(table_name = site_aggregates))]
130 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::site::Site)))]
131 #[cfg_attr(feature = "full", ts(export))]
132 /// Aggregate data for a site.
133 pub struct SiteAggregates {
139 pub communities: i64,
140 /// The number of users with any activity in the last day.
141 pub users_active_day: i64,
142 /// The number of users with any activity in the last week.
143 pub users_active_week: i64,
144 /// The number of users with any activity in the last month.
145 pub users_active_month: i64,
146 /// The number of users with any activity in the last half year.
147 pub users_active_half_year: i64,