-
Notifications
You must be signed in to change notification settings - Fork 898
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
default to using inline sql views for reports #18822
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.
This one comment is the only thing I have to add for this. I think it is fine that are enabling this across the board and having it go through it through the QE test cycle, but I might be biased and missing something.
app/models/miq_report/generator.rb
Outdated
@@ -319,7 +319,7 @@ def generate_basic_results(options = {}) | |||
|
|||
## add in virtual attributes that can be calculated from sql | |||
rbac_opts[:extra_cols] = va_sql_cols unless va_sql_cols.blank? | |||
rbac_opts[:use_sql_view] = true if db_options && db_options[:use_sql_view] | |||
rbac_opts[:use_sql_view] = true unless db_options && db_options[:use_sql_view] == false |
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.
Two alternative ideas on how to handle this:
Option 1
Maybe make this "falsey", where we still do an "existence" check, but then simply check that the value is falsey:
rbac_opts[:use_sql_view] = true unless db_options.has_key?(:use_sql_view) && !db_options[:use_sql_view]
Option 2
Alternatively, we can change this in Rbac
so that this code here only sets it if it exists:
rbac_opts[:use_sql_view] = db_options[:use_sql_view] if db_options.has_key?(:use_sql_view)
And then in Rbac.search
, we do a:
def search(options={})
# ...
options[:use_sql_view] ||= true
# ...
end
Or do you think that is too heavy handed?
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.
Or something like this:
rbac_opts[:use_sql_view] = db_options[:use_sql_view] != false
I do think there is some merit to considering option 2 though.
You can't memoize with a false value though, so perhaps something like:
def search(options={})
# ...
options[:use_sql_view] = true unless options[:use_sql_view] == false
# ...
end
EDIT: Haha, I typod... had = false
instead of == false
@kbrock You might want to look into the tests failures on this one, as they seem to be related to this change. We might possibly want to run the test suite of the API and UI with this change in place prior to merging. |
I also suggest running the manageiq-ui-classic specs as the UI is heavily dependent on reports |
6a8edc8
to
0e5652b
Compare
Thnx I've run this through all the views (which should be the only real issue) but running a full test suite is a good idea. will do today |
also, @NickLaMuro |
WIP: waiting for new release of virtual attributes |
all passed. |
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.
Honestly, I don't have the capacity to put up any real stink about this PR.
I am still unsure why this is in existence to begin with, since it doesn't seem to be helping fix anything in particular for the Rails upgrade effort and there is no BZ associated, so I only can assume this is one of "Keenan's random musings" I am all to familiar with. Also, the example of "one case where this makes things better" seems very pseudo science-y and far from definitive evidence this will make the world a better place.
But I also just had something merged that broke in ten different ways and I probably am being a hypocrite, so maybe just do what you want, man. The Dude abides.
app/models/miq_report/generator.rb
Outdated
@@ -319,7 +319,7 @@ def generate_basic_results(options = {}) | |||
|
|||
## add in virtual attributes that can be calculated from sql | |||
rbac_opts[:extra_cols] = va_sql_cols unless va_sql_cols.blank? | |||
rbac_opts[:use_sql_view] = true if db_options && db_options[:use_sql_view] | |||
rbac_opts[:use_sql_view] = db_options&.key?(:use_sql_view) ? db_options[:use_sql_view] : true |
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.
Nevermind, I am out... review this yourself since you used the &
operator...
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 also why I hate this operator since it just adds cognitive load as a result of saving key strokes...
But anyway, is this now defaulting to true
, and favoring the option value when it is present?
So the above change then translates to this:
- rbac_opts[:use_sql_view] = true if db_options && db_options[:use_sql_view]
+ rbac_opts[:use_sql_view] = true
+ rbac_opts[:use_sql_view] = db_options[:use_sql_view] if db_options && db_options.key?(:use_sql_view)
Correct?
Edit: I realized that I reviewed this PR weeks ago, and commented on this specific line, so this most likely was a "yes" to answering the last question.
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.
But anyway, is this now defaulting to true, and favoring the option value when it is present?
Change the turbo button from op-in to an op-out. So all screens will have it.
-- the after section of the description
Yes, sorry that rubocop wanted me to change it:
- rbac_opts[:use_sql_view] = db_options && db_options.key?(:use_sql_view) ? db_options[:use_sql_view] : true
+ rbac_opts[:use_sql_view] = db_options&.db_options.key?(:use_sql_view) ? db_options[:use_sql_view] : true
I will change to:
- rbac_opts[:use_sql_view] = db_options && db_options.key?(:use_sql_view) ? db_options[:use_sql_view] : true
+ rbac_opts[:use_sql_view] = db_options == nil || db_options.fetch(:use_sql_view) { true }
app/models/miq_report/search.rb
Outdated
@@ -97,7 +97,7 @@ def paged_view_search(options = {}) | |||
) | |||
search_options.merge!(:limit => limit, :offset => offset, :order => order) if order | |||
search_options[:extra_cols] = va_sql_cols if va_sql_cols.present? | |||
search_options[:use_sql_view] = true if db_options && db_options[:use_sql_view] | |||
search_options[:use_sql_view] = db_options&.key?(:use_sql_view) ? db_options[:use_sql_view] : true |
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.
ugh... again!!
... and to be honest, this is the primary use case of that method (since && . => &.)
Nope, doesn't make it better, and still looks like and overloaded version of the bitwise AND operator in my eyes.
e7d6267
to
b3babcd
Compare
for reports and the report data (right hand of screen) allow the use of inline sql views (aka the "turbo button") when there are virtual attributes in the primary query, they get run for every row (even those not brought back) this option allows rbac to optimize the query in these cases to run the virtual attributes in an outer query, so they only get run for the few rows brought back
virtual attributes should no contain aliases It should contain a grouping (parens on the outside) This alias was added due to a bug in virtual attributes that did not properly quote alias values. Now that that has been fixed, the alias can be removed.
Checked commits kbrock/manageiq@eb53085~...9dc5b0c with ruby 2.3.3, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0 |
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.
Seems fine to me. Been provided some context out of band, so I am more comfortable approving this PR now. 🐑 🇮🇹
@@ -318,7 +318,7 @@ def generate_basic_results(options = {}) | |||
|
|||
## add in virtual attributes that can be calculated from sql | |||
rbac_opts[:extra_cols] = va_sql_cols unless va_sql_cols.blank? | |||
rbac_opts[:use_sql_view] = true if db_options && db_options[:use_sql_view] | |||
rbac_opts[:use_sql_view] = db_options.nil? || db_options.fetch(:use_sql_view) { true } |
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.
We talked about this out of band, but this could technically be:
rbac_opts[:use_sql_view] = db_options.nil? || db_options.fetch(:use_sql_view, true)
But I don't think it is worth another rebase and CI run, and rubocop
doesn't seem to care. Just an FYI.
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.
LGTM
💣 🔥 🚒 |
Note: We have our first victim after merging this: https://travis-ci.org/ManageIQ/manageiq-ui-classic/jobs/547432152 Quick fix done in #18892 |
Depends upon:
Overview
When we include virtual attributes in a query, it runs the query for every row in the result set.
For pages like the services explorer, this is very slow.
We solved this issue by introducing inline views and only running the virtual attribute for the rows in the result set. #18543 introduced it as an opt-in feature.
This has affectionately been called the "Turbo Button".
Before
Only use the improved performance in certain screens since there is a concern this may break screens. Only the Services screen has opted-in for improved performance (on hammer and master/ivanchuk)
After
Change the turbo button from op-in to an op-out. So all screens will have it.
This PR did require a change to virtual attributes and custom attribute: Fixed a bug in Virtual Attributes to properly escape sql aliases. Removed work around for said bug in Custom Attributes.
Numbers
For one example, see #18543
This will have impact on any screen that displays counts. e.g.: explorers for ems, host, and vms.