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

Make attribute last_scan_on sql-friendly #18198

Merged
merged 2 commits into from
Nov 15, 2018

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented Nov 14, 2018

last_scan_on is used in 21 product/views/*.yml screens.

This PR converts last_scan_on from a ruby method to virtual_attribute.

This uncovered a bug in virtual_attribute's virtual_delegate. If you delegate to an association that has a select() defined, then the sql generated for the sub select is invalid:

sub-select returns 2 columns - expected 1

So this fixes the bug and converts last_scan_on to a virtual attribute.

Disclaimer: @NickLaMuro already fixed the main performance problem for https://bugzilla.redhat.com/show_bug.cgi?id=1648412 - but this adds a little to the performance effort.

Oh, and for the record. this is a +5/-15 PR - if I didn't need to add so many missing tests

@kbrock kbrock force-pushed the virtual_attr_last_scan_on branch 2 times, most recently from 5230c2d to 97c041f Compare November 14, 2018 17:29
Copy link
Member

@NickLaMuro NickLaMuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good and makes sense to me. Kinda stinks we have to make a alias_method to virtual_delegate, but I think that isn't really a big deal at the end of the day.

My request for changes are just around some things I found in the specs.

spec/lib/extensions/ar_virtual_spec.rb Outdated Show resolved Hide resolved
spec/lib/extensions/ar_virtual_spec.rb Outdated Show resolved Hide resolved
spec/models/mixins/drift_state_mixin_spec.rb Show resolved Hide resolved
spec/models/mixins/drift_state_mixin_spec.rb Outdated Show resolved Hide resolved
spec/models/mixins/drift_state_mixin_spec.rb Show resolved Hide resolved
spec/models/mixins/drift_state_mixin_spec.rb Outdated Show resolved Hide resolved
spec/models/mixins/drift_state_mixin_spec.rb Outdated Show resolved Hide resolved
spec/models/mixins/drift_state_mixin_spec.rb Outdated Show resolved Hide resolved
associations can have scopes, and those can include select clauses.

When one of those relations are used, the sub-select generated will
contains too many columns:

    sub-select returns 2 columns - expected 1

This change ensures only 1 column is in the virtual_attribute sub-select.
Copy link
Member

@NickLaMuro NickLaMuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More typos and such.

spec/models/mixins/drift_state_mixin_spec.rb Outdated Show resolved Hide resolved
spec/models/mixins/drift_state_mixin_spec.rb Outdated Show resolved Hide resolved
spec/models/mixins/drift_state_mixin_spec.rb Outdated Show resolved Hide resolved
spec/models/mixins/drift_state_mixin_spec.rb Outdated Show resolved Hide resolved
spec/models/mixins/drift_state_mixin_spec.rb Outdated Show resolved Hide resolved
This makes the drift state columns virtual

This is used by the Host-host.yml and 21 screen views
@kbrock
Copy link
Member Author

kbrock commented Nov 15, 2018

Thanks @NickLaMuro - these read much better

@miq-bot
Copy link
Member

miq-bot commented Nov 15, 2018

Checked commits kbrock/manageiq@aae11e5~...1387ffe with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
6 files checked, 0 offenses detected
Everything looks fine. 🏆

@NickLaMuro
Copy link
Member

NickLaMuro commented Nov 15, 2018

@kbrock outside of my review, I am thinking that this should be a hard hammer/no, because of the changes to ar_virtual.rb, and I would like that to stew on developer environments for a while to reduce risk. Seem reasonable?

Also, thanks for making all the fixes!


let(:host) { FactoryGirl.create(:host) }

let(:drift_states) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but if this is a let! then you don't need to call it in any of the below methods for "setup"

Copy link
Member

@Fryguy Fryguy Nov 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nvm...I didn't see that one test expressly can't have that...

That being said, perhaps there can be a context "with some drift states" around all of the tests that need that setup?

Again, it's minor...won't let it hold up a merge.

@Fryguy Fryguy merged commit 5fca169 into ManageIQ:master Nov 15, 2018
@Fryguy Fryguy added this to the Sprint 99 Ending Nov 19, 2018 milestone Nov 15, 2018
@Fryguy Fryguy self-assigned this Nov 15, 2018
@kbrock kbrock deleted the virtual_attr_last_scan_on branch November 15, 2018 19:40
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