Adding forum sort for post_aggregates. Fixes #1312 (#1400)

* Adding forum sort for post_aggregates. Fixes #1312

* Changing sort name from forum to MostComments.
pull/1406/head
Dessalines 3 years ago committed by GitHub
parent f4d33389a5
commit 6bb4f0b41f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -164,6 +164,7 @@ pub enum SortType {
TopMonth,
TopYear,
TopAll,
MostComments,
}
#[derive(EnumString, ToString, Debug, Serialize, Deserialize, Clone)]

@ -380,7 +380,7 @@ impl<'a> CommentQueryBuilder<'a> {
SortType::Hot | SortType::Active => query
.order_by(hot_rank(comment_aggregates::score, comment_aggregates::published).desc())
.then_order_by(comment_aggregates::published.desc()),
SortType::New => query.order_by(comment::published.desc()),
SortType::New | SortType::MostComments => query.order_by(comment::published.desc()),
SortType::TopAll => query.order_by(comment_aggregates::score.desc()),
SortType::TopYear => query
.filter(comment::published.gt(now - 1.years()))

@ -363,6 +363,7 @@ impl<'a> PostQueryBuilder<'a> {
.then_order_by(hot_rank(post_aggregates::score, post_aggregates::published).desc())
.then_order_by(post_aggregates::published.desc()),
SortType::New => query.then_order_by(post_aggregates::published.desc()),
SortType::MostComments => query.then_order_by(post_aggregates::comments.desc()),
SortType::TopAll => query.then_order_by(post_aggregates::score.desc()),
SortType::TopYear => query
.filter(post::published.gt(now - 1.years()))

@ -270,7 +270,7 @@ impl<'a> UserMentionQueryBuilder<'a> {
SortType::Hot | SortType::Active => query
.order_by(hot_rank(comment_aggregates::score, comment_aggregates::published).desc())
.then_order_by(comment_aggregates::published.desc()),
SortType::New => query.order_by(comment::published.desc()),
SortType::New | SortType::MostComments => query.order_by(comment::published.desc()),
SortType::TopAll => query.order_by(comment_aggregates::score.desc()),
SortType::TopYear => query
.filter(comment::published.gt(now - 1.years()))

@ -110,7 +110,7 @@ impl<'a> UserQueryBuilder<'a> {
SortType::Active => query
.order_by(user_aggregates::comment_score.desc())
.then_order_by(user_::published.desc()),
SortType::New => query.order_by(user_::published.desc()),
SortType::New | SortType::MostComments => query.order_by(user_::published.desc()),
SortType::TopAll => query.order_by(user_aggregates::comment_score.desc()),
SortType::TopYear => query
.filter(user_::published.gt(now - 1.years()))

@ -0,0 +1 @@
drop index idx_post_aggregates_comments;

@ -0,0 +1 @@
create index idx_post_aggregates_comments on post_aggregates (comments desc);
Loading…
Cancel
Save