Fix invalid batch iteration

This commit is contained in:
Max Wofford 2025-03-05 02:41:14 -05:00
parent b303861397
commit e34019d050

View file

@ -4,11 +4,11 @@ class OneTime::GenerateUniqueHeartbeatHashesJob < ApplicationJob
def perform
ActiveRecord::Base.transaction do
# batch update the fields_hash
Heartbeat.where(fields_hash: nil).find_each_batch(of: 1000) do |batch|
batch.each do |heartbeat|
heartbeat.send(:set_fields_hash!)
heartbeat.save!
end
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)
end
end