Grant badges in `import:ensure_consistency` rake task

It disables notifications for all badges. We don't want overwhelm migrated users with lots of notifications about badges. And this also speeds up badge granting...
This commit is contained in:
Gerhard Schlager 2024-07-11 12:13:25 +02:00 committed by cocococosti
parent 8d6ab2a098
commit e86d4690a2
No known key found for this signature in database
GPG Key ID: FDEE4E9ED2BD9B89
1 changed files with 30 additions and 0 deletions

View File

@ -2,6 +2,9 @@
# Use http://tatiyants.com/pev/#/plans/new if you want to optimize a query
require "colored2"
require_relative "../../app/services/badge_granter"
task "import:ensure_consistency" => :environment do
log "Starting..."
@ -27,6 +30,7 @@ task "import:ensure_consistency" => :environment do
update_topic_users
update_topic_featured_users
create_category_definitions
grant_badges
# run_jobs
@ -717,6 +721,32 @@ task "import:update_avatars_from_sso" => :environment do
status_thread.join
end
class NoNotificationBadeGranter < BadgeGranter
def self.suppress_notification?(badge, granted_at, skip_new_user_tips)
true
end
end
def grant_badges
return unless SiteSetting.enable_badges
Badge.enabled.find_each do |b|
begin
start_time = Time.now
print " - Backfilling #{b.name}"
NoNotificationBadeGranter.backfill(b)
puts ": #{(Time.now - start_time).to_i} seconds"
rescue StandardError
print ": "
puts "failed".red
end
end
BadgeGranter.revoke_ungranted_titles!
UserBadge.ensure_consistency! # Badge granter sometimes uses raw SQL, so hooks do not run. Clean up data
UserStat.update_distinct_badge_count
end
def run_jobs
log "Running jobs"