noosfero | Private community has public content (#515)

Rodrigo Souto gitlab at gitlab.com
Thu May 7 12:30:05 BRT 2015


New comment for Merge Request 515

https://gitlab.com/noosfero/noosfero/merge_requests/515#note_1202211


Rodrigo Souto

Try to avoid as hard as you can iterations on big arrays such as this 'blocks'. In order to do this, ruby will load the whole array on memory and it may slow down your migration heavily. Also, this iteration generates N sql update queries (where N is the number of blocks).

Another important issues is to avoid using ruby code on migrations because they may break with a different code base in the future (although we already have plenty of "ruby-coded" migrations already...  :P).

This migration can be improved with something like this:
```ruby
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')

execute("UPDATE blocks SET display_user = 'followers' FROM blocks AS b INNER JOIN boxes ON b.box_id = boxes.id INNER JOIN profiles ON boxes.owner_id = profiles.id WHERE blocks.id = b.id AND boxes.owner_type = 'Profile' AND NOT profiles.public_profile AND b.type != 'MainBlock'")
```

Please test it and update your merge request.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150507/2fcaffa2/attachment.html>


More information about the Noosfero-dev mailing list