Skip to content
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 4 commits into from
Oct 10, 2019
Merged

Improve references #19127

merged 4 commits into from
Oct 10, 2019

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented Aug 9, 2019

Overview

Use references properly

We pass a hash of relations to include(). We pass that same parameter to references(). 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) to references(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:

  1. include: the models/columns that are in the SELECT clause.
  2. 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 to Rbac to allow the caller to distinguish between the 2 scenarios. If references is not passed into Rbac, the code assumes the existing behavior and adds the tables to the references().

This is a remake of #18848 and attempting to address performance issues on both the vm and services page

@kbrock
Copy link
Member Author

kbrock commented Aug 22, 2019

Rubocop: using name get_include to line up with get_include_or_find
ignoring

lib/rbac.rb Outdated Show resolved Hide resolved
lib/rbac/filterer.rb Outdated Show resolved Hide resolved
lib/rbac/filterer.rb Outdated Show resolved Hide resolved
@Fryguy
Copy link
Member

Fryguy commented Aug 26, 2019

Looks good to me.

@kbrock kbrock changed the title [WIP] Improve references Improve references Aug 26, 2019
@kbrock kbrock added ivanchuk/no and removed wip labels Aug 26, 2019
@Fryguy
Copy link
Member

Fryguy commented Aug 26, 2019

Can you also verify that the UI tests pass (since they still have the reports tests there?)

@kbrock kbrock force-pushed the rbac_no_references branch 2 times, most recently from 064242e to 3638143 Compare September 27, 2019 16:56
kbrock added 4 commits October 3, 2019 14:14
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 kbrock force-pushed the rbac_no_references branch from 3638143 to 296b73f Compare October 4, 2019 13:56
@miq-bot
Copy link
Member

miq-bot commented Oct 4, 2019

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
5 files checked, 1 offense detected

app/models/miq_report/generator.rb

@jrafanie jrafanie merged commit e24682e into ManageIQ:master Oct 10, 2019
@jrafanie jrafanie added this to the Sprint 122 Ending Oct 14, 2019 milestone Oct 10, 2019
@jrafanie jrafanie self-assigned this Oct 10, 2019
@kbrock kbrock deleted the rbac_no_references branch October 11, 2019 15:14
NickLaMuro added a commit to NickLaMuro/manageiq that referenced this pull request Feb 4, 2020
…ces"

This reverts commit e24682e, reversing
changes made to cd215c7.
@chessbyte chessbyte mentioned this pull request Mar 31, 2020
38 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants