Browse Source

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

* Adding forum sort for post_aggregates. Fixes #1312

* Changing sort name from forum to MostComments.
downstream
Dessalines 12 months ago
committed by GitHub
parent
commit
6bb4f0b41f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      crates/db_queries/src/lib.rs
  2. 2
      crates/db_views/src/comment_view.rs
  3. 1
      crates/db_views/src/post_view.rs
  4. 2
      crates/db_views_actor/src/user_mention_view.rs
  5. 2
      crates/db_views_actor/src/user_view.rs
  6. 1
      migrations/2021-01-31-050334_add_forum_sort_index/down.sql
  7. 1
      migrations/2021-01-31-050334_add_forum_sort_index/up.sql

1
crates/db_queries/src/lib.rs

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

2
crates/db_views/src/comment_view.rs

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

1
crates/db_views/src/post_view.rs

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

2
crates/db_views_actor/src/user_mention_view.rs

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

2
crates/db_views_actor/src/user_view.rs

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

1
migrations/2021-01-31-050334_add_forum_sort_index/down.sql

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

1
migrations/2021-01-31-050334_add_forum_sort_index/up.sql

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