Commit a3c427e81661ae172e790a19dcee188b592a4b3d

Authored by Rodrigo Souto
1 parent 1ab07b35

fix-yaml-migration: use find_each to reduce memory consumption

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