mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
23 lines
558 B
Ruby
23 lines
558 B
Ruby
# 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)
|
|
User.reset_counters(user_id, :points)
|
|
rescue ActiveRecord::RecordNotFound
|
|
Rails.logger.warn "User #{user_id} not found, skipping counter cache update"
|
|
end
|
|
end
|