fix: robust jsonb target post matching in get_recent_target_posts
This commit is contained in:
+13
-7
@@ -220,13 +220,19 @@ class Repository:
|
||||
rows = await conn.fetch(
|
||||
"""
|
||||
SELECT * FROM posts
|
||||
WHERE (
|
||||
status = 'published'
|
||||
OR target_channel_id = $1
|
||||
OR published_to::text LIKE '%"target_id": ' || $1 || '%'
|
||||
)
|
||||
AND ($2::BIGINT IS NULL OR id != $2)
|
||||
AND is_deleted = FALSE
|
||||
WHERE is_deleted = FALSE
|
||||
AND ($2::BIGINT IS NULL OR id != $2)
|
||||
AND (
|
||||
target_channel_id = $1
|
||||
OR (
|
||||
published_to IS NOT NULL
|
||||
AND jsonb_typeof(published_to) = 'array'
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM jsonb_array_elements(published_to) elem
|
||||
WHERE (elem->>'target_id')::bigint = $1
|
||||
)
|
||||
)
|
||||
)
|
||||
ORDER BY COALESCE(published_at, created_at) DESC, id DESC
|
||||
LIMIT $3;
|
||||
""",
|
||||
|
||||
Reference in New Issue
Block a user