]> Untitled Git - lemmy.git/blob - migrations/2021-01-05-200932_add_hot_rank_indexes/up.sql
Dont use sha hash for password reset token (fixes #3491) (#3795)
[lemmy.git] / migrations / 2021-01-05-200932_add_hot_rank_indexes / up.sql
1 -- Need to add immutable to the hot_rank function in order to index by it
2 -- Rank = ScaleFactor * sign(Score) * log(1 + abs(Score)) / (Time + 2)^Gravity
3 CREATE OR REPLACE FUNCTION hot_rank (score numeric, published timestamp without time zone)
4     RETURNS integer
5     AS $$
6 BEGIN
7     -- hours_diff:=EXTRACT(EPOCH FROM (timezone('utc',now()) - published))/3600
8     RETURN floor(10000 * log(greatest (1, score + 3)) / power(((EXTRACT(EPOCH FROM (timezone('utc', now()) - published)) / 3600) + 2), 1.8))::integer;
9 END;
10 $$
11 LANGUAGE plpgsql
12 IMMUTABLE;
13
14 -- Post_aggregates
15 CREATE INDEX idx_post_aggregates_stickied_hot ON post_aggregates (stickied DESC, hot_rank (score, published) DESC, published DESC);
16
17 CREATE INDEX idx_post_aggregates_hot ON post_aggregates (hot_rank (score, published) DESC, published DESC);
18
19 CREATE INDEX idx_post_aggregates_stickied_active ON post_aggregates (stickied DESC, hot_rank (score, newest_comment_time) DESC, newest_comment_time DESC);
20
21 CREATE INDEX idx_post_aggregates_active ON post_aggregates (hot_rank (score, newest_comment_time) DESC, newest_comment_time DESC);
22
23 CREATE INDEX idx_post_aggregates_stickied_score ON post_aggregates (stickied DESC, score DESC);
24
25 CREATE INDEX idx_post_aggregates_score ON post_aggregates (score DESC);
26
27 CREATE INDEX idx_post_aggregates_stickied_published ON post_aggregates (stickied DESC, published DESC);
28
29 CREATE INDEX idx_post_aggregates_published ON post_aggregates (published DESC);
30
31 -- Comment
32 CREATE INDEX idx_comment_published ON comment (published DESC);
33
34 -- Comment_aggregates
35 CREATE INDEX idx_comment_aggregates_hot ON comment_aggregates (hot_rank (score, published) DESC, published DESC);
36
37 CREATE INDEX idx_comment_aggregates_score ON comment_aggregates (score DESC);
38
39 -- User
40 CREATE INDEX idx_user_published ON user_ (published DESC);
41
42 -- User_aggregates
43 CREATE INDEX idx_user_aggregates_comment_score ON user_aggregates (comment_score DESC);
44
45 -- Community
46 CREATE INDEX idx_community_published ON community (published DESC);
47
48 -- Community_aggregates
49 CREATE INDEX idx_community_aggregates_hot ON community_aggregates (hot_rank (subscribers, published) DESC, published DESC);
50
51 CREATE INDEX idx_community_aggregates_subscribers ON community_aggregates (subscribers DESC);
52