]> Untitled Git - lemmy.git/blob - migrations/2021-01-05-200932_add_hot_rank_indexes/down.sql
Speedup CI (#3852)
[lemmy.git] / migrations / 2021-01-05-200932_add_hot_rank_indexes / down.sql
1 -- Rank = ScaleFactor * sign(Score) * log(1 + abs(Score)) / (Time + 2)^Gravity
2 CREATE OR REPLACE FUNCTION hot_rank (score numeric, published timestamp without time zone)
3     RETURNS integer
4     AS $$
5 BEGIN
6     -- hours_diff:=EXTRACT(EPOCH FROM (timezone('utc',now()) - published))/3600
7     RETURN floor(10000 * log(greatest (1, score + 3)) / power(((EXTRACT(EPOCH FROM (timezone('utc', now()) - published)) / 3600) + 2), 1.8))::integer;
8 END;
9 $$
10 LANGUAGE plpgsql;
11
12 DROP INDEX idx_post_aggregates_hot, idx_post_aggregates_stickied_hot, idx_post_aggregates_active, idx_post_aggregates_stickied_active, idx_post_aggregates_score, idx_post_aggregates_stickied_score, idx_post_aggregates_published, idx_post_aggregates_stickied_published, idx_comment_published, idx_comment_aggregates_hot, idx_comment_aggregates_score, idx_user_published, idx_user_aggregates_comment_score, idx_community_published, idx_community_aggregates_hot, idx_community_aggregates_subscribers;
13