fix: robust jsonb target post matching in get_recent_target_posts
This commit is contained in:
+12
-6
@@ -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;
|
||||||
""",
|
""",
|
||||||
|
|||||||
Reference in New Issue
Block a user