1 DROP INDEX idx_post_aggregates_newest_comment_time, idx_post_aggregates_stickied_newest_comment_time, idx_post_aggregates_stickied_comments;
3 ALTER TABLE post_aggregates
4 DROP COLUMN newest_comment_time;
6 ALTER TABLE post_aggregates RENAME COLUMN newest_comment_time_necro TO newest_comment_time;
8 CREATE OR REPLACE FUNCTION post_aggregates_comment_count ()
13 IF (TG_OP = 'INSERT') THEN
17 comments = comments + 1
19 pa.post_id = NEW.post_id;
20 -- A 2 day necro-bump limit
24 newest_comment_time = NEW.published
26 pa.post_id = NEW.post_id
27 AND published > ('now'::timestamp - '2 days'::interval);
28 ELSIF (TG_OP = 'DELETE') THEN
29 -- Join to post because that post may not exist anymore
33 comments = comments - 1
38 AND pa.post_id = OLD.post_id;