Commit 920a3d7348c02e2bfed57b646101c06ae166b7ff

Authored by Rodrigo Souto
1 parent 617f3a2f

content_privacy: further optimizations on migration

db/migrate/20150319114233_change_default_content_privacy.rb
1 class ChangeDefaultContentPrivacy < ActiveRecord::Migration 1 class ChangeDefaultContentPrivacy < ActiveRecord::Migration
2 def up 2 def up
3 - ids = execute("SELECT id from profiles WHERE NOT public_profile")  
4 - profiles_ids = ids.map { |p| p["id"] }  
5 - unless ids.num_tuples.zero?  
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|  
13 - block.display_user = 'followers'  
14 - block.save  
15 - end 3 + update_sql('UPDATE articles SET published = (1>2), show_to_followers = (1=1)
  4 + FROM profiles WHERE articles.profile_id = profiles.id AND
  5 + NOT profiles.public_profile AND articles.published = (1=1)')
  6 +
  7 + Block.select('blocks.*').joins("INNER JOIN boxes ON blocks.box_id = boxes.id
  8 + INNER JOIN profiles ON boxes.owner_id = profiles.id AND boxes.owner_type = 'Profile'").
  9 + where("NOT profiles.public_profile AND blocks.type != 'MainBlock'").find_each do |block|
  10 + block.display_user = 'followers'
  11 + block.save
16 end 12 end
17 change_column :articles, :show_to_followers, :boolean, :default => true 13 change_column :articles, :show_to_followers, :boolean, :default => true
18 end 14 end