修改徽章查询以包含未列出主题?

你好,我正在尝试创建一个徽章查询,以便当有人回复一个“未列出”(UNLISTED)的帖子时授予徽章。

遗憾的是,常规查询似乎由于某种原因忽略了“未列出”的帖子,因此没有颁发徽章。

以下是相关的查询,与上文相同:

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 是我想要的主题
  (:backfill OR p.id IN (:post_ids) )

这是我收到的错误信息:

No Badges to be assigned.

Unique  (cost=25.87..25.88 rows=2 width=16)
  ->  Sort  (cost=25.87..25.87 rows=2 width=16)
        Sort Key: p.user_id
        ->  Hash Join  (cost=6.73..25.86 rows=2 width=16)
              Hash Cond: (t.category_id = c.id)
              ->  Nested Loop  (cost=4.32..23.44 rows=4 width=20)
                    ->  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)
                    ->  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[])))
                          ->  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)
              ->  Hash  (cost=2.21..2.21 rows=16 width=4)
                    ->  Seq Scan on categories c  (cost=0.00..2.21 rows=16 width=4)
                          Filter: (allow_badges AND (NOT read_restricted))

我该如何修改我的查询,使其不忽略“未列出”的帖子?

非常感谢您的时间。

尝试将

FROM badge_posts p

修改为

FROM posts p

badge_posts 表不包含未列出的帖子,也不包含在私密分类中创建的帖子。