1 DROP TRIGGER post_aggregates_comment_set_deleted ON comment;
3 DROP FUNCTION post_aggregates_comment_deleted;
5 CREATE OR REPLACE FUNCTION post_aggregates_comment_count ()
10 IF (TG_OP = 'INSERT') THEN
14 comments = comments + 1,
15 newest_comment_time = NEW.published
17 pa.post_id = NEW.post_id;
18 -- A 2 day necro-bump limit
22 newest_comment_time_necro = NEW.published
24 pa.post_id = NEW.post_id
25 AND published > ('now'::timestamp - '2 days'::interval);
26 ELSIF (TG_OP = 'DELETE') THEN
27 -- Join to post because that post may not exist anymore
31 comments = comments - 1
36 AND pa.post_id = OLD.post_id;