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, 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.
31 pub controversy_rank: f64,
34 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
35 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
36 #[cfg_attr(feature = "full", diesel(table_name = community_aggregates))]
39 diesel(belongs_to(crate::source::community::Community))
41 #[cfg_attr(feature = "full", ts(export))]
42 /// Aggregate data for a community.
43 pub struct CommunityAggregates {
45 pub community_id: CommunityId,
49 pub published: chrono::NaiveDateTime,
50 /// The number of users with any activity in the last day.
51 pub users_active_day: i64,
52 /// The number of users with any activity in the last week.
53 pub users_active_week: i64,
54 /// The number of users with any activity in the last month.
55 pub users_active_month: i64,
56 /// The number of users with any activity in the last year.
57 pub users_active_half_year: i64,
61 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone, Default)]
62 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
63 #[cfg_attr(feature = "full", diesel(table_name = person_aggregates))]
64 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))]
65 #[cfg_attr(feature = "full", ts(export))]
66 /// Aggregate data for a person.
67 pub struct PersonAggregates {
69 pub person_id: PersonId,
72 pub comment_count: i64,
73 pub comment_score: i64,
76 #[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
77 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
78 #[cfg_attr(feature = "full", diesel(table_name = post_aggregates))]
79 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
80 #[cfg_attr(feature = "full", ts(export))]
81 /// Aggregate data for a post.
82 pub struct PostAggregates {
89 pub published: chrono::NaiveDateTime,
90 /// A newest comment time, limited to 2 days, to prevent necrobumping
91 pub newest_comment_time_necro: chrono::NaiveDateTime,
92 /// The time of the newest comment in the post.
93 pub newest_comment_time: chrono::NaiveDateTime,
94 /// If the post is featured on the community.
95 pub featured_community: bool,
96 /// If the post is featured on the site / to local.
97 pub featured_local: bool,
99 pub hot_rank_active: i32,
100 pub community_id: CommunityId,
101 pub creator_id: PersonId,
102 pub controversy_rank: f64,
105 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
106 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
107 #[cfg_attr(feature = "full", diesel(table_name = person_post_aggregates))]
108 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))]
109 /// Aggregate data for a person's post.
110 pub struct PersonPostAggregates {
112 pub person_id: PersonId,
114 /// The number of comments they've read on that post.
116 /// This is updated to the current post comment count every time they view a post.
117 pub read_comments: i64,
118 pub published: chrono::NaiveDateTime,
121 #[derive(Clone, Default)]
122 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
123 #[cfg_attr(feature = "full", diesel(table_name = person_post_aggregates))]
124 pub struct PersonPostAggregatesForm {
125 pub person_id: PersonId,
127 pub read_comments: i64,
128 pub published: Option<chrono::NaiveDateTime>,
131 #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
132 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
133 #[cfg_attr(feature = "full", diesel(table_name = site_aggregates))]
134 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::site::Site)))]
135 #[cfg_attr(feature = "full", ts(export))]
136 /// Aggregate data for a site.
137 pub struct SiteAggregates {
143 pub communities: i64,
144 /// The number of users with any activity in the last day.
145 pub users_active_day: i64,
146 /// The number of users with any activity in the last week.
147 pub users_active_week: i64,
148 /// The number of users with any activity in the last month.
149 pub users_active_month: i64,
150 /// The number of users with any activity in the last half year.
151 pub users_active_half_year: i64,