¿Modificar la consulta de insignias para incluir temas no listados?

Hola, estoy intentando crear una consulta de insignia que otorgue una insignia cuando alguien responde a una publicación NO LISTADA.

Lamentablemente, parece que la consulta regular simplemente ignora las publicaciones “NO LISTADAS” por alguna razón y no otorga las insignias.

Aquí está la consulta en cuestión, es la misma que la anterior:

SELECT
DISTINCT ON (p.user_id)
p.user_id, p.id post_id, p.created_at granted_at
FROM badge_posts p
WHERE p.topic_id = 81 AND -- 81 es el tema que quiero
  (:backfill OR p.id IN (:post_ids) )

Y aquí está el error que obtengo:

No hay insignias que asignar.

Unique  (cost=25.87..25.88 rows=2 width=16)
  -\u003e  Sort  (cost=25.87..25.87 rows=2 width=16)
        Sort Key: p.user_id
        -\u003e  Hash Join  (cost=6.73..25.86 rows=2 width=16)
              Hash Cond: (t.category_id = c.id)
              -\u003e  Nested Loop  (cost=4.32..23.44 rows=4 width=20)
                    -\u003e  Index Scan using topics_pkey on topics t  (cost=0.14..8.16 rows=1 width=8)
                          Index Cond: (id = 81)
                          Filter: ((deleted_at IS NULL) AND visible)
                    -\u003e  Bitmap Heap Scan on posts p  (cost=4.18..15.24 rows=4 width=20)
                          Recheck Cond: (topic_id = 81)
                          Filter: ((deleted_at IS NULL) AND (post_type = ANY ('{1,2,3}'::integer[])))
                          -\u003e  Bitmap Index Scan on index_posts_on_topic_id_and_sort_order  (cost=0.00..4.17 rows=4 width=0)
                                Index Cond: (topic_id = 81)
              -\u003e  Hash  (cost=2.21..2.21 rows=16 width=4)
                    -\u003e  Seq Scan on categories c  (cost=0.00..2.21 rows=16 width=4)
                          Filter: (allow_badges AND (NOT read_restricted))

¿Cómo puedo modificar mi consulta para NO ignorar las publicaciones no listadas?

Muchas gracias por tu tiempo.

1 me gusta

Intenta cambiar

FROM badge_posts p

por

FROM posts p

La tabla badge_posts no incluye publicaciones no listadas ni publicaciones creadas en categorías privadas.

6 Me gusta