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
+12 -6
View File
@@ -220,13 +220,19 @@ class Repository:
rows = await conn.fetch( rows = await conn.fetch(
""" """
SELECT * FROM posts SELECT * FROM posts
WHERE ( WHERE is_deleted = FALSE
status = 'published'
OR target_channel_id = $1
OR published_to::text LIKE '%"target_id": ' || $1 || '%'
)
AND ($2::BIGINT IS NULL OR id != $2) AND ($2::BIGINT IS NULL OR id != $2)
AND is_deleted = FALSE 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 ORDER BY COALESCE(published_at, created_at) DESC, id DESC
LIMIT $3; LIMIT $3;
""", """,