mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 20:31:19 +00:00
Feature add three six and nine months options backend (#3226)
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
This commit is contained in:
parent
50efb1d519
commit
f5209fffc1
6 changed files with 46 additions and 1 deletions
|
@ -63,6 +63,9 @@ pub enum SortType {
|
||||||
TopHour,
|
TopHour,
|
||||||
TopSixHour,
|
TopSixHour,
|
||||||
TopTwelveHour,
|
TopTwelveHour,
|
||||||
|
TopThreeMonths,
|
||||||
|
TopSixMonths,
|
||||||
|
TopNineMonths,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
|
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
|
||||||
|
|
|
@ -259,7 +259,10 @@ pub fn post_to_comment_sort_type(sort: SortType) -> CommentSortType {
|
||||||
| SortType::TopAll
|
| SortType::TopAll
|
||||||
| SortType::TopWeek
|
| SortType::TopWeek
|
||||||
| SortType::TopYear
|
| SortType::TopYear
|
||||||
| SortType::TopMonth => CommentSortType::Top,
|
| SortType::TopMonth
|
||||||
|
| SortType::TopThreeMonths
|
||||||
|
| SortType::TopSixMonths
|
||||||
|
| SortType::TopNineMonths => CommentSortType::Top,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -430,6 +430,18 @@ impl<'a> PostQuery<'a> {
|
||||||
.filter(post_aggregates::published.gt(now - 12.hours()))
|
.filter(post_aggregates::published.gt(now - 12.hours()))
|
||||||
.then_order_by(post_aggregates::score.desc())
|
.then_order_by(post_aggregates::score.desc())
|
||||||
.then_order_by(post_aggregates::published.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)?;
|
let (limit, offset) = limit_and_offset(self.page, self.limit)?;
|
||||||
|
|
|
@ -122,6 +122,15 @@ impl<'a> PersonQuery<'a> {
|
||||||
SortType::TopTwelveHour => query
|
SortType::TopTwelveHour => query
|
||||||
.filter(person::published.gt(now - 12.hours()))
|
.filter(person::published.gt(now - 12.hours()))
|
||||||
.order_by(person_aggregates::comment_score.desc()),
|
.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)?;
|
let (limit, offset) = limit_and_offset(self.page, self.limit)?;
|
||||||
|
|
|
@ -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');
|
||||||
|
|
||||||
|
-- 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__;
|
|
@ -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';
|
Loading…
Reference in a new issue