From 664ce08dc8721dfd6a9a935455e54c6f7d3fbb3f Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Fri, 9 Mar 2018 15:46:02 +0100 Subject: [PATCH] [Fix #1543] simplify request and provide progress feedback --- lib/tasks/2018_03_06_clean_html_textareas.rake | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/tasks/2018_03_06_clean_html_textareas.rake b/lib/tasks/2018_03_06_clean_html_textareas.rake index 37ff84579..ae66755ba 100644 --- a/lib/tasks/2018_03_06_clean_html_textareas.rake +++ b/lib/tasks/2018_03_06_clean_html_textareas.rake @@ -5,12 +5,17 @@ namespace :'2018_03_06_clean_html_textareas' do include ActionView::Helpers::TextHelper include HtmlToStringHelper - types_de_champ = TypeDeChamp.joins(:champ) - .where(type_champ: "textarea") - .where("champs.value LIKE '%<%'") + champs = Champ.joins(:type_de_champ) + .where(types_de_champ: { type_champ: "textarea" }) + .where("value LIKE '%<%'") - types_de_champ.find_each do |tdc| - tdc.champ.each { |c| c.update_column(:value, html_to_string(c.value)) } + total = champs.count + + champs.find_each(batch_size: 100).with_index do |c, i| + if (i % 100) == 0 + print "Champ #{i}/#{total}\n" + end + c.update_column(:value, html_to_string(c.value)) end end end