Fix get_latest_posts_per_board query
- put back order by clause (need that!) - use left joins which still return rows if there are no threads or posts on the board yet. - move is_missing_attachments flag into join condition (thanks deepseek)
This commit is contained in:
parent
f4652eecbb
commit
4dd29a72b6
|
@ -282,15 +282,15 @@ SELECT DISTINCT ON (b.board_id)
|
|||
p.post_id,
|
||||
p.board_post_id,
|
||||
p.creation_time,
|
||||
p.body,
|
||||
t.thread_id,
|
||||
t.board_thread_id
|
||||
FROM boards b
|
||||
LEFT JOIN threads t ON t.board_id = b.board_id
|
||||
LEFT JOIN posts p ON p.thread_id = t.thread_id AND p.is_missing_attachments = false
|
||||
ORDER BY b.board_id, p.creation_time DESC NULLS LAST;
|
||||
ORDER BY b.board_id, p.creation_time DESC;
|
||||
|
||||
|
||||
-- for Sync
|
||||
CREATE OR REPLACE FUNCTION get_latest_posts_per_board()
|
||||
RETURNS TABLE (
|
||||
board_id int,
|
||||
|
@ -312,9 +312,9 @@ RETURNS TABLE (
|
|||
t.thread_id,
|
||||
t.board_thread_id
|
||||
FROM boards b
|
||||
JOIN threads t ON t.board_id = b.board_id
|
||||
JOIN posts p ON p.thread_id = t.thread_id
|
||||
WHERE p.is_missing_attachments = false;
|
||||
LEFT JOIN threads t ON t.board_id = b.board_id
|
||||
LEFT JOIN posts p ON p.thread_id = t.thread_id AND p.is_missing_attachments = false
|
||||
ORDER BY b.board_id, p.creation_time DESC;
|
||||
$$ LANGUAGE sql STABLE;
|
||||
|
||||
SELECT * FROM get_latest_posts_per_board();
|
||||
|
|
|
@ -402,6 +402,7 @@ RETURNS SETOF catalog_grid_result AS $$
|
|||
$$ LANGUAGE sql STABLE;
|
||||
|
||||
|
||||
-- for Sync
|
||||
CREATE OR REPLACE FUNCTION get_latest_posts_per_board()
|
||||
RETURNS TABLE (
|
||||
board_id int,
|
||||
|
@ -423,9 +424,9 @@ RETURNS TABLE (
|
|||
t.thread_id,
|
||||
t.board_thread_id
|
||||
FROM boards b
|
||||
JOIN threads t ON t.board_id = b.board_id
|
||||
JOIN posts p ON p.thread_id = t.thread_id
|
||||
WHERE p.is_missing_attachments = false;
|
||||
LEFT JOIN threads t ON t.board_id = b.board_id
|
||||
LEFT JOIN posts p ON p.thread_id = t.thread_id AND p.is_missing_attachments = false
|
||||
ORDER BY b.board_id, p.creation_time DESC;
|
||||
$$ LANGUAGE sql STABLE;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue