]> Untitled Git - lemmy.git/blobdiff - crates/db_views/src/comment_view.rs
Adding hot_rank columns in place of function sorting. (#2952)
[lemmy.git] / crates / db_views / src / comment_view.rs
index 700d58f36cb0bb0fbed305c83729e1532e4f9d10..6ac629b5a02d41f8bd0dbe7684b79211e4d27b1f 100644 (file)
@@ -36,7 +36,7 @@ use lemmy_db_schema::{
     post::Post,
   },
   traits::JoinView,
-  utils::{functions::hot_rank, fuzzy_search, get_conn, limit_and_offset_unlimited, DbPool},
+  utils::{fuzzy_search, get_conn, limit_and_offset_unlimited, DbPool},
   CommentSortType,
   ListingType,
 };
@@ -312,7 +312,9 @@ impl<'a> CommentQuery<'a> {
       query = query.filter(local_user_language::language_id.is_not_null());
 
       // Don't show blocked communities or persons
-      query = query.filter(community_block::person_id.is_null());
+      if self.post_id.is_none() {
+        query = query.filter(community_block::person_id.is_null());
+      }
       query = query.filter(person_block::person_id.is_null());
     }
 
@@ -344,9 +346,7 @@ impl<'a> CommentQuery<'a> {
     };
 
     query = match self.sort.unwrap_or(CommentSortType::Hot) {
-      CommentSortType::Hot => query
-        .then_order_by(hot_rank(comment_aggregates::score, comment_aggregates::published).desc())
-        .then_order_by(comment_aggregates::published.desc()),
+      CommentSortType::Hot => query.then_order_by(comment_aggregates::hot_rank.desc()),
       CommentSortType::New => query.then_order_by(comment::published.desc()),
       CommentSortType::Old => query.then_order_by(comment::published.asc()),
       CommentSortType::Top => query.order_by(comment_aggregates::score.desc()),
@@ -907,6 +907,7 @@ mod tests {
         downvotes: 0,
         published: agg.published,
         child_count: 5,
+        hot_rank: 1728,
       },
     }
   }