Skip to content

Commit

Permalink
Fix heroku rate limits on memory usage?
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJackson-Oslo committed Sep 26, 2024
1 parent b6f05f5 commit da3af14
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions db/migrate/20240925180933_add_score_to_space_facility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ class AddScoreToSpaceFacility < ActiveRecord::Migration[7.1]
def up
add_column :space_facilities, :score, :integer, default: 0

total_count = SpaceFacility.count.to_i
processed_count = 0
# In a transaction, calculate score for all space facilities
SpaceFacility.transaction do
count = SpaceFacility.count.to_i
SpaceFacility.all.each_with_index do |space_facility, index|
print "\rCalculating score for #{index + 1} / #{count} "
space_facility.calculate_score
SpaceFacility.find_in_batches(batch_size: 200) do |space_facilities|
SpaceFacility.transaction do
space_facilities.each do |space_facility|
space_facility.calculate_score
processed_count += 1
print "\rCalculated score for #{processed_count} / #{total_count}\r "
end
end
end
end
Expand Down

0 comments on commit da3af14

Please sign in to comment.