-
Notifications
You must be signed in to change notification settings - Fork 900
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
Modify MiqExpression Contains to work for Rails 5.2 #20110
Conversation
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 am good with this I think. I have a few clarification questions outside of this review, but it is mostly double checking I understand what problem is being solved, and I think what you have here works.
.where(limiter_query) | ||
|
||
conn = main_model.connection | ||
sql = if ActiveRecord.version.to_s >= "5.2" |
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.
You know what, I will concede on this for now since it is such a small area we are dealing with (instead of 50 lines of visitor code that was only for 5.1 compatibility).
That said, I think we should delete this right away as part of #20076 if we are planning to merge this into master
right away. I would prefer this conditional not sticking around forever.
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.
Yes, great idea. Once this is merged, let's drop this conditional in #20076
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.
For this PR, is Travis set up to test BOTH Rails 5.1 and 5.2? Or is the current PR being tested on Rails 5.1 and #20076 will validate on Rails 5.2?
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.
This PR is still testing against Rails 5.1.
We have a few branches doing cross repo testing that have the branch from #20076 in it:
https://travis-ci.org/github/jrafanie/manageiq-cross_repo-tests/builds/670576839
ManageIQ/manageiq-cross_repo-tests#114
Which are validating it there, but we will confirm this works in 5.2 again when #20076 is rebased again, un-WIP'd, and ready for a final review.
expect(sql).to be_nil | ||
end | ||
|
||
it "can't generate the SQL for multi level contains with a scope" do |
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.
This is not something new, I take it. We are just adding specs to confirm this existing functionality, correct?
In what way? It looks like valid SQL to me, so I assume it is a generation issue that we are fixing, correct? Or the previous way we generated things used a removed (I may have never understood what your were solving for Rails 5.2... only that you were solving "something"...) |
rails suggests model.where(id: model.joins(:other_model).where('a=b')) we did the same. this method expects arel coming back, that is the reason we used the arel nodes. using primary_attribute.in(...) botched up the in clause, so we resorted to the longer version of declaring the in clause. wish it was not joining to Vm, but that is the ruby produced.
a376ca6
to
edfe0ac
Compare
fixed 2 (minor) cops. |
Checked commits kbrock/manageiq@6f099e9~...edfe0ac with ruby 2.5.7, rubocop 0.69.0, haml-lint 0.28.0, and yamllint |
Merging since this passes against 5.1 on master and we've tested it with cross repo on 5.2 in the past. We will address the points raised here in the 5.2 PR: #20076 |
Follow up to ManageIQ#20110 Related: ManageIQ#20032
Modify MiqExpression Contains to work for Rails 5.2 (cherry picked from commit cff8306)
Jansa backport details:
|
Follow up to ManageIQ#20110 Related: ManageIQ#20032
Overview
Alternative to #20051 Addresses #20032
We need the sql for:
Rails typically formats
EXISTS
andCONTAINS
queries in the following way:There ends up being an extra join in there to
vms
, but it is using the rails framework instead of fighting it is a big win. We also have bigger performance battles to fight.The fix
In Rails 5.2, relations and bound variables work differently. So it was not simple to patch the work we did in
extract_where_values
andWhereExtractionVisitor
. It was simpler to change to a different approach that will work with rails 5.2.The changes do change the SQL produced. There is an extra join as a result, but the logic to get there is much simpler since we are not using a visitor to do it.
Before
After
The new approach does not use
Arel
and usesActiveRecord
with a few tweaks: