-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle cases where a Picture with that id doesn't exist #159
Conversation
b495212
to
6af81e0
Compare
@miq-bot add_labels blocker bug gaprindashvili/yes |
@bdunne Cannot apply the following label because they are not recognized: blocker bug gaprindashvili/yes |
2 similar comments
@bdunne Cannot apply the following label because they are not recognized: blocker bug gaprindashvili/yes |
@bdunne Cannot apply the following label because they are not recognized: blocker bug gaprindashvili/yes |
@@ -18,7 +18,7 @@ def up | |||
|
|||
say_with_time("Moving picture content from BinaryBlobs to the pictures table") do | |||
BinaryBlob.in_my_region.includes(:binary_blob_parts).where(:resource_type => "Picture").find_each do |blob| | |||
Picture.update(blob.resource_id, :content => blob.data, :extension => blob.data_type, :md5 => blob.md5) if blob.resource_id | |||
Picture.find_by(:id => blob.resource_id).try(:update_attributes!, :content => blob.data, :extension => blob.data_type, :md5 => blob.md5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to do
Picture.where(:id => blob.resource_id).update_all(:content => blob.data, :extension => blob.data_type, :md5 => blob.md5) if blob.resource_id
so you don't have to pull the Picture object and then update (2 queries + in memory object - basically an N+1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Yep, that's what I was trying to avoid all along. For some reason I didn't think to update_all
with a where
.
6af81e0
to
a7caf2f
Compare
a7caf2f
to
447c8a4
Compare
Checked commit bdunne@447c8a4 with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0 db/migrate/20180111162442_move_pictures_blobs_to_pictures.rb
|
Handle cases where a Picture with that id doesn't exist (cherry picked from commit 40c5ced) https://bugzilla.redhat.com/show_bug.cgi?id=1536046
Gaprindashvili backport details:
|
Supplement to #153
https://bugzilla.redhat.com/show_bug.cgi?id=1532286