thread->by_id() returns remark_tally and bump_tally

This commit is contained in:
swag 2023-05-12 22:15:33 -04:00
parent 0ee6423be8
commit c0895274b2
2 changed files with 15 additions and 7 deletions

View File

@ -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)

View File

@ -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
}