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