From 1a70b9fb978e5fc05496cc06b26bd9a35473559c Mon Sep 17 00:00:00 2001 From: r888888888 Date: Fri, 3 Jan 2014 17:08:00 -0800 Subject: [PATCH] optimize fix for last_commented_at --- script/fixes/025_last_commented_at.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/script/fixes/025_last_commented_at.rb b/script/fixes/025_last_commented_at.rb index 50c26af02..f73b36c6b 100644 --- a/script/fixes/025_last_commented_at.rb +++ b/script/fixes/025_last_commented_at.rb @@ -3,7 +3,11 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')) ActiveRecord::Base.connection.execute("set statement_timeout = 0") -ActiveRecord::Base.connection.execute("update posts set last_commented_at = (select max(c.created_at) from comments c where c.post_id = posts.id)") +0.upto(1585206 / 1000) do |i| + puts "updating posts #{i * 1000} to #{(i+1) * 1000}" + ActiveRecord::Base.connection.execute("update posts set last_commented_at = (select c.created_at from comments c where c.post_id = posts.id order by c.id desc limit 1) where posts.id between #{i * 1000} and #{(i+1) * 1000}") +end + TagImplication.find_each do |ti| ta = TagAlias.where("antecedent_name = ? AND status != ?", ti.antecedent_name, "pending").first if ta