mirror of
https://github.com/System-End/hackatime.git
synced 2026-04-20 00:35:22 +00:00
Fix invalid batch iteration
This commit is contained in:
parent
b303861397
commit
e34019d050
1 changed files with 5 additions and 5 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue