Lilly
August 26, 2023, 9:47pm
1
I’m not fully grasping the backfill condition so I am going get Lola Bot to explain.
2 Likes
The following badge is triggered on “when a user acts on a post”, this means “delta” applications will get the :post_ids
parameter.
SELECT p.user_id, p.id post_id, p.updated_at granted_at
FROM badge_posts p
WHERE p.like_count >= 25 AND
(:backfill OR p.id IN (:post_ids) )
The clause (:backfill OR p.id IN (:post_ids) )
allows us to filter the results. When the daily job runs :backfill
is true so the entire set is scanned. When the delta jobs run :backfill
is false and :post_ids
is set.
I was trying to get it to trigger on When a user acts on a post
, but I think my Reactions may be blocking that somehow? Anyway, Update Daily will work, and is less of a performance concern, I think
5 Likes
Lilly
August 26, 2023, 9:58pm
3
Yea it totally makes sense to me now. I think I prefer Sam’s explanation.
Can you explain backfill condition a little bit more Lola?
Lola Bot:
Certainly, Lilly! In Discourse, the :backfill
and :post_ids
are parameters used when running badge queries. They are used to control which posts are considered when awarding the badge.
:backfill
is a boolean parameter. When :backfill
is true
, the badge query is run against all the eligible posts in the database. This is typically used when you first create a badge or when you want to re-calculate who should have the badge based on all historical data.
:post_ids
is a list of post IDs. When :backfill
is false
, the badge query is only run against the posts whose IDs are in the :post_ids
list. This is typically used to check if a badge should be awarded based on a new post or a set of recent posts, rather than all posts.
The condition (:backfill OR p.id IN (:post_ids))
in the WHERE clause of the SQL query ensures that:
If :backfill
is true
, the condition will always be true
and all posts will be considered (because true OR anything
is always true
).
If :backfill
is false
, only the posts with IDs in the :post_ids
list will be considered (because false OR p.id IN (:post_ids)
will be true
only for the posts whose IDs are in the :post_ids
list).
This allows Discourse to efficiently award badges either based on all historical posts or based on a small set of recent posts, depending on the situation.
5 Likes
I think I need to look into which badge queries actually need it adding. I think if you’re using `Update Daily’ it’s not necessary:
2 Likes
system
(system)
Closed
September 25, 2023, 10:06pm
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.