Commit a3c427e81661ae172e790a19dcee188b592a4b3d
1 parent
1ab07b35
Exists in
master
and in
29 other branches
fix-yaml-migration: use find_each to reduce memory consumption
Showing
1 changed file
with
2 additions
and
3 deletions
Show diff stats
db/migrate/20140724134601_fix_yaml_encoding.rb
@@ -18,9 +18,8 @@ class FixYamlEncoding < ActiveRecord::Migration | @@ -18,9 +18,8 @@ class FixYamlEncoding < ActiveRecord::Migration | ||
18 | private | 18 | private |
19 | 19 | ||
20 | def self.fix_encoding(model, param) | 20 | def self.fix_encoding(model, param) |
21 | - result = model.all | ||
22 | - puts "Fixing #{result.count} rows of #{model} (#{param})" | ||
23 | - result.each do |r| | 21 | + puts "Fixing #{model.count} rows of #{model} (#{param})" |
22 | + model.find_each do |r| | ||
24 | begin | 23 | begin |
25 | yaml = r.send(param) | 24 | yaml = r.send(param) |
26 | # if deserialization failed then a string is returned | 25 | # if deserialization failed then a string is returned |