Commit 617f3a2f942fdd157ed1f05642bbcd8042dd6340

Authored by André Guedes
Committed by Rodrigo Souto
1 parent a710bcc7

Changed migration to use find_each batch update

db/migrate/20150319114233_change_default_content_privacy.rb
@@ -3,10 +3,13 @@ class ChangeDefaultContentPrivacy < ActiveRecord::Migration @@ -3,10 +3,13 @@ class ChangeDefaultContentPrivacy < ActiveRecord::Migration
3 ids = execute("SELECT id from profiles WHERE NOT public_profile") 3 ids = execute("SELECT id from profiles WHERE NOT public_profile")
4 profiles_ids = ids.map { |p| p["id"] } 4 profiles_ids = ids.map { |p| p["id"] }
5 unless ids.num_tuples.zero? 5 unless ids.num_tuples.zero?
6 - execute("UPDATE articles SET published = (1>2), show_to_followers = (1=1)  
7 - WHERE profile_id IN (#{profiles_ids.join(",")}) AND published")  
8 - blocks = Block.includes(:box).where(:boxes => {:owner_type => "Profile", :owner_id => profiles_ids}).where('type != ?', "MainBlock")  
9 - blocks.each do |block| 6 + execute('UPDATE articles SET published = (1>2), show_to_followers = (1=1)
  7 + FROM articles AS a INNER JOIN profiles ON a.profile_id = profiles.id
  8 + WHERE NOT profiles.public_profile AND articles.id = a.id AND a.published = (1=1)')
  9 + Block.includes(:box).where(
  10 + :boxes => {:owner_type => "Profile",
  11 + :owner_id => profiles_ids}).where(
  12 + 'type != ?', "MainBlock").find_each do |block|
10 block.display_user = 'followers' 13 block.display_user = 'followers'
11 block.save 14 block.save
12 end 15 end