fix: robust jsonb target post matching in get_recent_target_posts

This commit is contained in:
mamad
2026-08-28 22:16:18 +03:30
parent 9551ccce71
commit 2b4e476e2f
+13 -7
View File
@@ -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;
""",