-
Notifications
You must be signed in to change notification settings - Fork 897
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
Improve references #19127
Merged
Merged
Improve references #19127
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kbrock
force-pushed
the
rbac_no_references
branch
2 times, most recently
from
August 9, 2019 16:28
c7f779a
to
14b65ba
Compare
kbrock
force-pushed
the
rbac_no_references
branch
from
August 19, 2019 22:08
14b65ba
to
c4a35d4
Compare
Rubocop: using name |
Fryguy
reviewed
Aug 26, 2019
Fryguy
reviewed
Aug 26, 2019
Fryguy
reviewed
Aug 26, 2019
Fryguy
reviewed
Aug 26, 2019
Fryguy
reviewed
Aug 26, 2019
Looks good to me. |
Fryguy
approved these changes
Aug 26, 2019
Can you also verify that the UI tests pass (since they still have the reports tests there?) |
kbrock
force-pushed
the
rbac_no_references
branch
4 times, most recently
from
September 12, 2019 18:17
e581c4b
to
c8cb376
Compare
This was referenced Sep 13, 2019
Merged
kbrock
force-pushed
the
rbac_no_references
branch
from
September 19, 2019 16:29
c8cb376
to
6f84aa2
Compare
kbrock
force-pushed
the
rbac_no_references
branch
from
September 27, 2019 15:19
6f84aa2
to
90f5019
Compare
kbrock
force-pushed
the
rbac_no_references
branch
2 times, most recently
from
September 27, 2019 16:56
064242e
to
3638143
Compare
includes are for columns in the query includes_for_find are for the models used by the report views Reports merge the two concepts. But only the miq expression (where) or includes (select) need to be in the references. While includes_for_find only needs to preload the models for use in ruby. This allows each to be accessed in a report.
includes() are used in ruby references() are used by sql Tables used in the select or where clause need to be joined using references, joins, or outer_joins. Up until now, we've treated them as the same. But it is taxing to have so many tables in the query. So they are split apart. :include is used in the select column, so it is referenced miq_expression is used in the where clause, so it is referenced include_for_find is only used to preload models. --- If references are not passed in, it defaults to existing behavior. Meaning, all includes are in references. But if references are passed in, then only those tables are referenced()
:references are now passed for hopefully all rbac that also passes in include_for_find. Since the references are explicitly passed in, we don't want the code second guessing these decisions. Also, since not all tables are passed to references, there is no longer the need to come up with complicated logic to reduce the references passed into ActiveRecord
We are already passing conditions into Rbac.filtered, so the MiqExpression will be applied in rbac. There is no reason to also apply it to the where clause here. The reason for making this change now, is we are changing the way the references from an MiqExpression are added. (instead of using a hash, we're converting into an array) I prefer to make this code introduction in as few places as possible.
kbrock
force-pushed
the
rbac_no_references
branch
from
October 4, 2019 13:56
3638143
to
296b73f
Compare
Checked commits kbrock/manageiq@0edb041~...296b73f with ruby 2.4.6, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0 app/models/miq_report/generator.rb
|
jrafanie
approved these changes
Oct 10, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
references()
properly. Fix references pass 1 #19295 <== better description of the problemreferences()
properly Rbac no references array #19318references()
sparingly. <== This PRUse references properly
We pass a hash of relations to
include()
. We pass that same parameter toreferences()
. But, we should pass an array of table names rails references docs. This is undefined behavior. Rails currently puts all tables into the primary query.Change
references(hash)
toreferences(array)
. It also introduces a method that converts a hash of relations into an array of table names.Use references sparingly.
Reports reference tables in 2 ways:
include:
the models/columns that are in theSELECT
clause.include_for_find:
. the models that are used by the ruby view code.Only the
include
portion needs to actually be in the primary query.Introduce option
references
toRbac
to allow the caller to distinguish between the 2 scenarios. Ifreferences
is not passed intoRbac
, the code assumes the existing behavior and adds the tables to thereferences()
.This is a remake of #18848 and attempting to address performance issues on both the vm and services page