diff --git a/README.md b/README.md index 3028df9..fa7305f 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,9 @@ Run the tests locally (against development environment): ### (Lord knows there's TODOs I could be working on...) +1. Is `remark_tally` counting hidden remarks? Tried to add a `WHERE + NOT hidden_status` but that returns null, probably need a different + `JOIN` which may not be worth the trouble/processing 1. Implement tripcodes (moving this down in priority due to complexity...) 1. Return a text response instead of HTML if a `.txt` extension [is requested](https://docs.mojolicious.org/Mojolicious/Plugin/DefaultHelpers#respond_to) diff --git a/lib/PostText/Model/Thread.pm b/lib/PostText/Model/Thread.pm index c6dedba..231f566 100644 --- a/lib/PostText/Model/Thread.pm +++ b/lib/PostText/Model/Thread.pm @@ -71,13 +71,18 @@ sub by_id($self, $thread_id) { my $date_format = $self->date_format; $self->pg->db->query(<<~'END_SQL', $date_format, $thread_id)->hash; - SELECT thread_id AS id, - TO_CHAR(thread_date, ?) AS date, - thread_author AS author, - thread_title AS title, - thread_body AS body - FROM threads - WHERE thread_id = ?; + SELECT t.thread_id AS id, + TO_CHAR(t.thread_date, ?) AS date, + t.thread_author AS author, + t.thread_title AS title, + t.thread_body AS body, + COUNT(r.*) AS remark_tally, + t.bump_tally AS bump_tally + FROM threads AS t + LEFT JOIN remarks AS r + ON t.thread_id = r.thread_id + WHERE t.thread_id = ? + GROUP BY t.thread_id; END_SQL }