1 -- Need to add immutable to the hot_rank function in order to index by it
3 -- Rank = ScaleFactor * sign(Score) * log(1 + abs(Score)) / (Time + 2)^Gravity
4 create or replace function hot_rank(
6 published timestamp without time zone)
9 -- hours_diff:=EXTRACT(EPOCH FROM (timezone('utc',now()) - published))/3600
10 return floor(10000*log(greatest(1,score+3)) / power(((EXTRACT(EPOCH FROM (timezone('utc',now()) - published))/3600) + 2), 1.8))::integer;
16 create index idx_post_published on post (published desc);
17 create index idx_post_stickied on post (stickied desc);
20 create index idx_post_aggregates_hot on post_aggregates (hot_rank(score, published) desc, published desc);
21 create index idx_post_aggregates_active on post_aggregates (hot_rank(score, newest_comment_time) desc, newest_comment_time desc);
22 create index idx_post_aggregates_score on post_aggregates (score desc);
25 create index idx_comment_published on comment (published desc);
28 create index idx_comment_aggregates_hot on comment_aggregates (hot_rank(score, published) desc, published desc);
29 create index idx_comment_aggregates_score on comment_aggregates (score desc);
32 create index idx_user_published on user_ (published desc);
35 create index idx_user_aggregates_comment_score on user_aggregates (comment_score desc);
38 create index idx_community_published on community (published desc);
40 -- Community_aggregates
41 create index idx_community_aggregates_hot on community_aggregates (hot_rank(subscribers, published) desc, published desc);
42 create index idx_community_aggregates_subscribers on community_aggregates (subscribers desc);