Commit 920a3d7348c02e2bfed57b646101c06ae166b7ff
1 parent
617f3a2f
Exists in
master
and in
26 other branches
content_privacy: further optimizations on migration
Showing
1 changed file
with
9 additions
and
13 deletions
Show diff stats
db/migrate/20150319114233_change_default_content_privacy.rb
1 | 1 | class ChangeDefaultContentPrivacy < ActiveRecord::Migration |
2 | 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 | 12 | end |
17 | 13 | change_column :articles, :show_to_followers, :boolean, :default => true |
18 | 14 | end | ... | ... |