1
mirror of https://gitlab.com/commento/commento.git synced 2025-06-29 22:56:37 -04:00

api,db: add comments count endpoint

Closes https://gitlab.com/commento/commento-ce/issues/27
This commit is contained in:
Adhityaa Chandrasekar
2018-09-23 00:40:06 -04:00
parent 299649cea2
commit 330131f390
6 changed files with 118 additions and 2 deletions

View File

@ -0,0 +1,15 @@
ALTER TABLE pages
ADD commentCount INTEGER NOT NULL DEFAULT 0;
CREATE OR REPLACE FUNCTION commentsInsertTriggerFunction() RETURNS TRIGGER AS $trigger$
BEGIN
UPDATE pages
SET commentCount = commentCount + 1
WHERE domain = new.domain AND path = new.path;
RETURN NEW;
END;
$trigger$ LANGUAGE plpgsql;
CREATE TRIGGER commentsInsertTrigger AFTER INSERT ON comments
FOR EACH ROW EXECUTE PROCEDURE commentsInsertTriggerFunction();