db: decrease comment count when a comment is deleted
Update commentsDeleteTriggerFunction in order to decrease the counter before deleting nested comments. Closes https://gitlab.com/commento/commento/issues/157
This commit is contained in:
parent
62340eb9c6
commit
4a8e90bd43
13
db/20190505191006-comment-count-decrease.sql
Normal file
13
db/20190505191006-comment-count-decrease.sql
Normal file
@ -0,0 +1,13 @@
|
||||
-- This trigger is called every time a comment is deleted, so the comment count for the page where the comment belong is updated
|
||||
CREATE OR REPLACE FUNCTION commentsDeleteTriggerFunction() RETURNS TRIGGER AS $trigger$
|
||||
BEGIN
|
||||
UPDATE pages
|
||||
SET commentCount = commentCount - 1
|
||||
WHERE domain = old.domain AND path = old.path;
|
||||
|
||||
DELETE FROM comments
|
||||
WHERE parentHex = old.commentHex;
|
||||
|
||||
RETURN NEW;
|
||||
END;
|
||||
$trigger$ LANGUAGE plpgsql;
|
Loading…
Reference in New Issue
Block a user