发帖徽章

Since there deliberately isn’t the concept of achievements for posting, I’ve managed to implement it on ours, since we had it on our old forums and some were complain about the lack thereof.

Generic version:

SELECT user_id, 0 post_id, current_timestamp granted_at 
FROM badge_posts  
WHERE (:backfill OR user_id IN (:user_ids) OR 0 NOT IN (:post_ids) )
GROUP BY user_id 
HAVING count(*) > 1000

Change the 1000 for whatever post limit you’re after. I’ve themed ours (due to the nature of our board) on powers of 2.

Note that this will (should) only count posts that are public (not in categories that are restricted or private messages) or otherwise unrestricted (checkbox on edit category ignoring badges)

Additionally, for our board I’ve had to exclude certain topics due to the nature of my charges:

SELECT user_id, 0 post_id, current_timestamp granted_at 
FROM badge_posts  
WHERE topic_id NOT IN (
   [elided]
) AND topic_id NOT IN (
   [elided]
) AND  (:backfill OR user_id IN (:user_ids) OR 0 NOT IN (:post_ids) )
GROUP BY user_id 
HAVING count(*) >= 2048

Edit: There was a problem with my queries - post_id is apparently required when this is triggered on post-related triggers.
See
https://meta.discourse.org/t/badges-sql-problem/19295

And

Edit 2: Added :backfill

14 个赞

I think I have the correct trigger condition here, actually:

    :backfill OR
    user_id IN (
        SELECT trigger_post.user_id FROM posts trigger_post WHERE trigger_post.id IN (:post_ids)
    )

You get the user id list from the list of triggered posts and filter on that.

4 个赞

Thanks. This is very helpful. I am also thinking about encouraging users to initiate discussions. I am messing around your query to count original posts with p.post_number = 1

我刚刚在这里发现了这个小技巧。我想为自己的特定类别发帖数量创建自定义徽章查询。如何修改此查询以包含特定类别 ID 的条件,使得仅统计特定类别中的帖子?

这应该是对此处第一个查询的修改,该查询基于在特定类别中创建主题来授予徽章。不同之处在于,我们基于特定类别中的帖子数量来授予徽章。

1 个赞

运行徽章查询预览时遇到此错误:

查询时出错。有什么办法可以修复它?

合同违规:
查询触发于帖子,但引用了 ':user_ids' 数组