2025-08-21 16:32:29 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
class DataMigrations::PrefillPointsCounterCacheJob < ApplicationJob
|
|
|
|
|
queue_as :data_migrations
|
|
|
|
|
|
|
|
|
|
def perform(user_id = nil)
|
|
|
|
|
if user_id
|
|
|
|
|
prefill_counter_for_user(user_id)
|
|
|
|
|
else
|
|
|
|
|
User.find_each(batch_size: 100) do |user|
|
|
|
|
|
prefill_counter_for_user(user.id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def prefill_counter_for_user(user_id)
|
2025-08-26 09:26:05 -04:00
|
|
|
User.reset_counters(user_id, :points)
|
2025-08-21 16:32:29 -04:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
|
Rails.logger.warn "User #{user_id} not found, skipping counter cache update"
|
|
|
|
|
end
|
|
|
|
|
end
|