TopAll,
MostComments,
NewComments,
+ TopHour,
+ TopSixHour,
+ TopTwelveHour,
}
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
SortType::Active | SortType::Hot => CommentSortType::Hot,
SortType::New | SortType::NewComments | SortType::MostComments => CommentSortType::New,
SortType::Old => CommentSortType::Old,
- SortType::TopDay
+ SortType::TopHour
+ | SortType::TopSixHour
+ | SortType::TopTwelveHour
+ | SortType::TopDay
| SortType::TopAll
| SortType::TopWeek
| SortType::TopYear
.filter(post_aggregates::published.gt(now - 1.days()))
.then_order_by(post_aggregates::score.desc())
.then_order_by(post_aggregates::published.desc()),
+ SortType::TopHour => query
+ .filter(post_aggregates::published.gt(now - 1.hours()))
+ .then_order_by(post_aggregates::score.desc())
+ .then_order_by(post_aggregates::published.desc()),
+ SortType::TopSixHour => query
+ .filter(post_aggregates::published.gt(now - 6.hours()))
+ .then_order_by(post_aggregates::score.desc())
+ .then_order_by(post_aggregates::published.desc()),
+ SortType::TopTwelveHour => query
+ .filter(post_aggregates::published.gt(now - 12.hours()))
+ .then_order_by(post_aggregates::score.desc())
+ .then_order_by(post_aggregates::published.desc()),
};
let (limit, offset) = limit_and_offset(self.page, self.limit)?;
SortType::TopDay => query
.filter(person::published.gt(now - 1.days()))
.order_by(person_aggregates::comment_score.desc()),
+ SortType::TopHour => query
+ .filter(person::published.gt(now - 1.hours()))
+ .order_by(person_aggregates::comment_score.desc()),
+ SortType::TopSixHour => query
+ .filter(person::published.gt(now - 6.hours()))
+ .order_by(person_aggregates::comment_score.desc()),
+ SortType::TopTwelveHour => query
+ .filter(person::published.gt(now - 12.hours()))
+ .order_by(person_aggregates::comment_score.desc()),
};
let (limit, offset) = limit_and_offset(self.page, self.limit)?;
--- /dev/null
+-- update the default sort type
+update local_user set default_sort_type = 'TopDay' where default_sort_type in ('TopHour', 'TopSixHour', 'TopTwelveHour');
+
+-- 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__;
\ No newline at end of file
--- /dev/null
+-- Update the enums
+ALTER TYPE sort_type_enum ADD VALUE 'TopHour';
+ALTER TYPE sort_type_enum ADD VALUE 'TopSixHour';
+ALTER TYPE sort_type_enum ADD VALUE 'TopTwelveHour';
\ No newline at end of file