From: Dessalines Date: Mon, 1 Feb 2021 16:53:44 +0000 (-0500) Subject: Adding forum sort for post_aggregates. Fixes #1312 (#1400) X-Git-Url: http://these/git/%7B%60https:/%24%7Bargs.pageFn.jump%20n%7D?a=commitdiff_plain;h=6bb4f0b41f25baafad4e40fe5df22647be19577e;p=lemmy.git Adding forum sort for post_aggregates. Fixes #1312 (#1400) * Adding forum sort for post_aggregates. Fixes #1312 * Changing sort name from forum to MostComments. --- diff --git a/crates/db_queries/src/lib.rs b/crates/db_queries/src/lib.rs index b0a73b7b..ebe7394c 100644 --- a/crates/db_queries/src/lib.rs +++ b/crates/db_queries/src/lib.rs @@ -164,6 +164,7 @@ pub enum SortType { TopMonth, TopYear, TopAll, + MostComments, } #[derive(EnumString, ToString, Debug, Serialize, Deserialize, Clone)] diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 111791d9..68eb0688 100644 --- a/crates/db_views/src/comment_view.rs +++ b/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())) diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 1d2526a0..d454fcbe 100644 --- a/crates/db_views/src/post_view.rs +++ b/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())) diff --git a/crates/db_views_actor/src/user_mention_view.rs b/crates/db_views_actor/src/user_mention_view.rs index 1e9e74ee..811af6e7 100644 --- a/crates/db_views_actor/src/user_mention_view.rs +++ b/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())) diff --git a/crates/db_views_actor/src/user_view.rs b/crates/db_views_actor/src/user_view.rs index acb8c4c8..2b85a63c 100644 --- a/crates/db_views_actor/src/user_view.rs +++ b/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())) diff --git a/migrations/2021-01-31-050334_add_forum_sort_index/down.sql b/migrations/2021-01-31-050334_add_forum_sort_index/down.sql new file mode 100644 index 00000000..9de29698 --- /dev/null +++ b/migrations/2021-01-31-050334_add_forum_sort_index/down.sql @@ -0,0 +1 @@ +drop index idx_post_aggregates_comments; diff --git a/migrations/2021-01-31-050334_add_forum_sort_index/up.sql b/migrations/2021-01-31-050334_add_forum_sort_index/up.sql new file mode 100644 index 00000000..61087388 --- /dev/null +++ b/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);