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

Feature add three six and nine months options backend #3226

Merged
merged 2 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/db_schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ pub enum SortType {
TopHour,
TopSixHour,
TopTwelveHour,
TopThreeMonths,
TopSixMonths,
TopNineMonths,
}

#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
Expand Down
5 changes: 4 additions & 1 deletion crates/db_schema/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,10 @@ pub fn post_to_comment_sort_type(sort: SortType) -> CommentSortType {
| SortType::TopAll
| SortType::TopWeek
| SortType::TopYear
| SortType::TopMonth => CommentSortType::Top,
| SortType::TopMonth
| SortType::TopThreeMonths
| SortType::TopSixMonths
| SortType::TopNineMonths => CommentSortType::Top,
}
}

Expand Down
12 changes: 12 additions & 0 deletions crates/db_views/src/post_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,18 @@ impl<'a> PostQuery<'a> {
.filter(post_aggregates::published.gt(now - 12.hours()))
.then_order_by(post_aggregates::score.desc())
.then_order_by(post_aggregates::published.desc()),
SortType::TopThreeMonths => query
.filter(post_aggregates::published.gt(now - 3.months()))
.then_order_by(post_aggregates::score.desc())
.then_order_by(post_aggregates::published.desc()),
SortType::TopSixMonths => query
.filter(post_aggregates::published.gt(now - 6.months()))
.then_order_by(post_aggregates::score.desc())
.then_order_by(post_aggregates::published.desc()),
SortType::TopNineMonths => query
.filter(post_aggregates::published.gt(now - 9.months()))
.then_order_by(post_aggregates::score.desc())
.then_order_by(post_aggregates::published.desc()),
};

let (limit, offset) = limit_and_offset(self.page, self.limit)?;
Expand Down
9 changes: 9 additions & 0 deletions crates/db_views_actor/src/person_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ impl<'a> PersonQuery<'a> {
SortType::TopTwelveHour => query
.filter(person::published.gt(now - 12.hours()))
.order_by(person_aggregates::comment_score.desc()),
SortType::TopThreeMonths => query
.filter(person::published.gt(now - 3.months()))
.order_by(person_aggregates::comment_score.desc()),
SortType::TopSixMonths => query
.filter(person::published.gt(now - 6.months()))
.order_by(person_aggregates::comment_score.desc()),
SortType::TopNineMonths => query
.filter(person::published.gt(now - 9.months()))
.order_by(person_aggregates::comment_score.desc()),
};

let (limit, offset) = limit_and_offset(self.page, self.limit)?;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- update the default sort type
update local_user set default_sort_type = 'TopDay' where default_sort_type in ('TopThreeMonths', 'TopSixMonths', 'TopNineMonths');

-- rename the old enum
alter type sort_type_enum rename to sort_type_enum__;
-- create the new enum
CREATE TYPE sort_type_enum AS ENUM ('Active', 'Hot', 'New', 'Old', 'TopDay', 'TopWeek', 'TopMonth', 'TopYear', 'TopAll', 'MostComments', 'NewComments');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should include the TopHour, TopSixHour and TopTwelveHour enums

Copy link
Contributor Author

@c-andy-candies c-andy-candies Jun 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I was not sure when I made the PR. Since now it has been merged, should I do another PR correcting it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually there's no take backsies with migrations, but I think in this case it's a down migration and is probably fine just opening a new PR with the hotfix of this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened a PR #3370


-- alter all you enum columns
alter table local_user
alter column default_sort_type type sort_type_enum using default_sort_type::text::sort_type_enum;

-- drop the old enum
drop type sort_type_enum__;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Update the enums
ALTER TYPE sort_type_enum ADD VALUE 'TopThreeMonths';
ALTER TYPE sort_type_enum ADD VALUE 'TopSixMonths';
ALTER TYPE sort_type_enum ADD VALUE 'TopNineMonths';