]> Untitled Git - lemmy.git/commitdiff
Adding forum sort for post_aggregates. Fixes #1312 (#1400)
authorDessalines <dessalines@users.noreply.github.com>
Mon, 1 Feb 2021 16:53:44 +0000 (11:53 -0500)
committerGitHub <noreply@github.com>
Mon, 1 Feb 2021 16:53:44 +0000 (11:53 -0500)
* Adding forum sort for post_aggregates. Fixes #1312

* Changing sort name from forum to MostComments.

crates/db_queries/src/lib.rs
crates/db_views/src/comment_view.rs
crates/db_views/src/post_view.rs
crates/db_views_actor/src/user_mention_view.rs
crates/db_views_actor/src/user_view.rs
migrations/2021-01-31-050334_add_forum_sort_index/down.sql [new file with mode: 0644]
migrations/2021-01-31-050334_add_forum_sort_index/up.sql [new file with mode: 0644]

index b0a73b7ba95068ba2e3433cdc32a9ee0b71591ff..ebe7394c9ffed493cd29a1761fcee1ee6713695c 100644 (file)
@@ -164,6 +164,7 @@ pub enum SortType {
   TopMonth,
   TopYear,
   TopAll,
+  MostComments,
 }
 
 #[derive(EnumString, ToString, Debug, Serialize, Deserialize, Clone)]
index 111791d93b4a0d896bd52ef235f2df5cae15efdb..68eb068855bbba0f4ea47b4f66935e2182212734 100644 (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()))
index 1d2526a0f29bc17f0bbe650452796543813d24de..d454fcbe034dbd5837e82a86e0d91b496fd6bf95 100644 (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()))
index 1e9e74ee27eb75ad437c714338e7c2fb72e1ddc2..811af6e75945ad81a49739dc3285bc6a6be96133 100644 (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()))
index acb8c4c8d4fbd26ba40d2335e3f05a686c996acd..2b85a63ce59ab3d2d90b071bdfb72d3c2a7dab91 100644 (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()))
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 (file)
index 0000000..9de2969
--- /dev/null
@@ -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 (file)
index 0000000..6108738
--- /dev/null
@@ -0,0 +1 @@
+create index idx_post_aggregates_comments on post_aggregates (comments desc);