From 62340eb9c6a6fd91fb3770fc66269d872226d6be Mon Sep 17 00:00:00 2001 From: Adhityaa Chandrasekar Date: Wed, 8 May 2019 22:28:20 -0700 Subject: [PATCH] comment_new.go: create page before inserting comment Fixes https://gitlab.com/commento/commento/issues/173 --- api/comment_count_test.go | 4 ++-- api/comment_new.go | 8 ++++---- db/20190508222848-reset-count.sql | 2 ++ 3 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 db/20190508222848-reset-count.sql diff --git a/api/comment_count_test.go b/api/comment_count_test.go index 89cc004..c4d3a35 100644 --- a/api/comment_count_test.go +++ b/api/comment_count_test.go @@ -20,8 +20,8 @@ func TestCommentCountBasics(t *testing.T) { return } - if counts["/path.html"] != 2 { - t.Errorf("expected count=2 got count=%d", counts["/path.html"]) + if counts["/path.html"] != 3 { + t.Errorf("expected count=3 got count=%d", counts["/path.html"]) return } } diff --git a/api/comment_new.go b/api/comment_new.go index 5cb3656..c31695f 100644 --- a/api/comment_new.go +++ b/api/comment_new.go @@ -30,6 +30,10 @@ func commentNew(commenterHex string, domain string, path string, parentHex strin html := markdownToHtml(markdown) + if err = pageNew(domain, path); err != nil { + return "", err + } + statement := ` INSERT INTO comments (commentHex, domain, path, commenterHex, parentHex, markdown, html, creationDate, state) @@ -41,10 +45,6 @@ func commentNew(commenterHex string, domain string, path string, parentHex strin return "", errorInternal } - if err = pageNew(domain, path); err != nil { - return "", err - } - return commentHex, nil } diff --git a/db/20190508222848-reset-count.sql b/db/20190508222848-reset-count.sql new file mode 100644 index 0000000..d3162f4 --- /dev/null +++ b/db/20190508222848-reset-count.sql @@ -0,0 +1,2 @@ +UPDATE pages +SET commentCount = commentCount + 1;