Make sure comments are sorted by hot_rank, then score. (#3667)

change-comment-default-lang-logic
Dessalines 2023-07-21 05:44:47 -04:00 committed by GitHub
parent ccc122100e
commit 623d81139e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 4 deletions

View File

@ -362,12 +362,10 @@ impl<'a> CommentQuery<'a> {
query = match self.sort.unwrap_or(CommentSortType::Hot) {
CommentSortType::Hot => query
.then_order_by(comment_aggregates::hot_rank.desc())
.then_order_by(comment_aggregates::published.desc()),
CommentSortType::Top => query
.order_by(comment_aggregates::score.desc())
.then_order_by(comment_aggregates::published.desc()),
.then_order_by(comment_aggregates::score.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()),
};
// Note: deleted and removed comments are done on the front side

View File

@ -0,0 +1,4 @@
drop index idx_comment_aggregates_hot, idx_comment_aggregates_score;
create index idx_comment_aggregates_hot on comment_aggregates (hot_rank desc, published desc);
create index idx_comment_aggregates_score on comment_aggregates (score desc, published desc);

View File

@ -0,0 +1,10 @@
-- Alter the comment_aggregates hot sort to sort by score after hot_rank.
-- Reason being, is that hot_ranks go to zero after a few days,
-- and then comments should be sorted by score, not published.
drop index idx_comment_aggregates_hot, idx_comment_aggregates_score;
create index idx_comment_aggregates_hot on comment_aggregates (hot_rank desc, score desc);
-- Remove published from this sort, its pointless
create index idx_comment_aggregates_score on comment_aggregates (score desc);