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

Add MiqPreloader.polymorphic_preload_for_child_classes #17457

Conversation

NickLaMuro
Copy link
Member

@NickLaMuro NickLaMuro commented May 21, 2018

This branch was extracted from #17354 to bring attention to the large addition to MiqPreloader, which adds a new method:

MiqPreloader.polymorphic_preload_for_child_classes

This is a specialized preloader for classes with polymorphic relationships that allows for targeted preloading for those specific class types on said polymorphic relationships. This allows for taking
advantage of those associations by allowing scopes to be applied to the specific relationships and subsequent calls to the relationship can have those query definitions applied.

This means you can do things like this:

irb> tree = ExtManagementSystem.last.fulltree_rels_arranged(:except_type => "VmOrTemplate")
#=> nodes ExtManagementSystem, EmsCluster, EmsFolder, and Host `relationship_type` records
irb> records = Relationship.flatten_arranged_rels(tree)
irb> hosts_scope = Host.select(Host.arel_table[Arel.star], :v_total_vms)
irb> preloaders_per_class = { EmsCluster => [:hosts, hosts_scope], Host => hosts_scope }
irb> MiqPreloader.polymorphic_preload_for_child_classes(records, nil, preloaders_per_class)
#=> Host records with have the `v_total_vms` column load, and hosts accessed through EmsCluster will as well

Links

@NickLaMuro NickLaMuro force-pushed the miq_preloader_polymorphic_improvements branch 2 times, most recently from 28af494 to 2f971d5 Compare May 21, 2018 18:41
This is a specialized preloader for classes with polymorphic
relationships that allows for targeted preloading for those specific
class types on said polymorphic relationships.  This allows for taking
advantage of those associations by allowing scopes to be applied to the
specific relationships and subsequent calls to the relationship can have
those query definitions applied.
@miq-bot
Copy link
Member

miq-bot commented May 21, 2018

Checked commit NickLaMuro@2f971d5 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 4 offenses detected

lib/miq_preloader.rb

@NickLaMuro
Copy link
Member Author

NickLaMuro commented May 21, 2018

The above rubocop violations existed in the code that this was extracted from (minus the Module.new {...} multi-line block one, that one just looked better). To make it more obvious the changes I was pulling from, they have been left as is for the time being.

If desired, I could make a commit to fix the rubocop violations in the offending bits in lib/extensions/ar_virtual.rb and avoid the ones presented here, but felt slightly out of scope to do so.

@NickLaMuro
Copy link
Member Author

@miq-bot add_label performance
@miq-bot assign @Fryguy

@Fryguy Assigning you as I figured you would be curious about this change over all (will be at least cc'ing you in the related PRs as well). Feel free to reassign to @kbrock or someone else if you don't want to review.

cc @kbrock @syncrou

@miq-bot
Copy link
Member

miq-bot commented Nov 26, 2018

This pull request has been automatically closed because it has not been updated for at least 6 months.

Feel free to reopen this pull request if these changes are still valid.

Thank you for all your contributions!

@miq-bot miq-bot closed this Nov 26, 2018
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.

3 participants