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

* Adding forum sort for post_aggregates. Fixes #1312

* Changing sort name from forum to MostComments.
This commit is contained in:
Dessalines 2021-02-01 11:53:44 -05:00 committed by GitHub
parent f4d33389a5
commit 6bb4f0b41f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 7 additions and 3 deletions

View file

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

View file

@ -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()))

View file

@ -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()))

View file

@ -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()))

View file

@ -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()))

View file

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

View file

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