Update generate_unique_heartbeat_hashes_job.rb

This commit is contained in:
Max Wofford 2025-03-05 02:43:42 -05:00
parent e34019d050
commit cd17161326

View file

@ -3,12 +3,9 @@ class OneTime::GenerateUniqueHeartbeatHashesJob < ApplicationJob
def perform
ActiveRecord::Base.transaction do
# batch update the fields_hash
Heartbeat.where(fields_hash: nil).find_in_batches(of: 5000) do |batch|
updates = batch.map do |heartbeat|
[ heartbeat.id, heartbeat.send(:set_fields_hash) ]
end.to_h
Heartbeat.where(id: updates.keys).update_all(fields_hash: updates)
Heartbeat.where(fields_hash: nil).find_each do |heartbeat|
heartbeat.send(:set_fields_hash!)
heartbeat.save!
end
end