PERF: Enqueue Job::BackfillBadge in Jobs::BadgeGrant (#30945)

This commit updates the `Jobs::BadgeGrant` scheduled job to enqueue on
`Job::BackfillBadge` regular job for each enabled badge on the site.

The rationale for this change is that we started seeing the
`Jobs::BadgeGrant` job taking hours on sites with lots of enabled badges
as well as users because the job was backfilling all enabled badges
serially within the job. This is bad as it means that a `mini_scheduler`
thread is tied up
by this job thus reducing the overall capacity of `mini_scheduler` for
hours.
This commit is contained in:
Alan Guo Xiang Tan
2025-01-24 09:35:01 +08:00
committed by GitHub
parent b195b1c8a6
commit 3e4eac0fed
9 changed files with 149 additions and 60 deletions

View File

@ -144,7 +144,7 @@ class UserBadgesController < ApplicationController
UserBadge.where(user_id: user_badge.user_id, badge_id: user_badge.badge_id).update_all(
is_favorite: !user_badge.is_favorite,
)
UserBadge.update_featured_ranks!(user_badge.user_id)
UserBadge.update_featured_ranks!([user_badge.user_id])
end
private