Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/db_views/src/comment_view.rs
Expand Up @@ -345,7 +345,9 @@ impl<'a> CommentQuery<'a> {
};

query = match self.sort.unwrap_or(CommentSortType::Hot) {
CommentSortType::Hot => query.then_order_by(comment_aggregates::hot_rank.desc()),
CommentSortType::Hot => query
.then_order_by(comment_aggregates::hot_rank.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()),
Expand Down
@@ -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);
@@ -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);