-
Notifications
You must be signed in to change notification settings - Fork 898
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix (HACK) N+1 with get_ems_metadata_tree hosts
When building out hosts in get_ems_metadata_tree, there is a call to `.v_total_vms` on the host records for each EmsCluster. This ends up causing an N+1 since the hosts from the tree data, and the `v_total_vms` is a virtual_attribute that has to count all of the Vms for a given host. This change does a few things to avoid this (all of which are terrible and none of which I am terribly proud of): First, it adds an addition to `MiqPreloader`, which is a new method `polymorphic_preload_for_child_classes`. This allows requesting a polymorphic relation to preload (top level only), and then you can provide a collection of class names and scopes that can be applied for the resulting classes that are return from the original preload for further preloading on the child records. This is then used by `miq_request_workflow.rb` and the Relationship model and mixin to apply the scope and records to the original query and records returned from it, preventing the N+1.
- Loading branch information
1 parent
d986cb6
commit 7bc4621
Showing
4 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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