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...) ### (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. Implement tripcodes (moving this down in priority due to complexity...)
1. Return a text response instead of HTML if a `.txt` extension [is 1. Return a text response instead of HTML if a `.txt` extension [is
requested](https://docs.mojolicious.org/Mojolicious/Plugin/DefaultHelpers#respond_to) 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; my $date_format = $self->date_format;
$self->pg->db->query(<<~'END_SQL', $date_format, $thread_id)->hash; $self->pg->db->query(<<~'END_SQL', $date_format, $thread_id)->hash;
SELECT thread_id AS id, SELECT t.thread_id AS id,
TO_CHAR(thread_date, ?) AS date, TO_CHAR(t.thread_date, ?) AS date,
thread_author AS author, t.thread_author AS author,
thread_title AS title, t.thread_title AS title,
thread_body AS body t.thread_body AS body,
FROM threads COUNT(r.*) AS remark_tally,
WHERE thread_id = ?; 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 END_SQL
} }