-
Notifications
You must be signed in to change notification settings - Fork 898
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
Use MiqPreloader/Relationship improvements in MiqRequestWorkflow #17461
Closed
NickLaMuro
wants to merge
4
commits into
ManageIQ:master
from
NickLaMuro:miq_preloader_relationship_mixin_improvements_in_miq_request_workflow
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2f971d5
Add MiqPreloader.polymorphic_preload_for_child_classes
NickLaMuro 4980f77
Move miq_preloader_spec tree building logic to shared_context
NickLaMuro 5d016ab
Use .polymorphic_preload_for_child_classes in .fulltree_arranged
NickLaMuro aaf21ce
Add polymorphic relationship improvements in MiqRequestWorkflow
NickLaMuro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
68 changes: 68 additions & 0 deletions
68
spec/support/examples_group/shared_context_for_ems_metadata_tree.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
shared_context "simple ems_metadata tree" do | ||
##################### | ||
# Context Variables # | ||
##################### | ||
|
||
# These can be updated to increase the amount of data in the tree | ||
|
||
let(:cluster_count) { 2 } | ||
let(:hosts_per_cluster) { 2 } | ||
let(:vms_per_host) { 2 } | ||
|
||
############### | ||
# Base models # | ||
############### | ||
|
||
let(:ems) { FactoryGirl.create(:ems_infra) } | ||
let(:clusters) { FactoryGirl.create_list(:ems_cluster, cluster_count, :ext_management_system => ems) } | ||
|
||
let(:hosts) do | ||
hosts = [] | ||
clusters.each do |cluster| | ||
hosts += FactoryGirl.create_list(:host, hosts_per_cluster, | ||
:ext_management_system => ems, | ||
:ems_cluster => cluster) | ||
end | ||
hosts | ||
end | ||
|
||
let(:vms) do | ||
vms = [] | ||
hosts.each do |host| | ||
vms += FactoryGirl.create_list(:vm, vms_per_host, | ||
:ext_management_system => ems, | ||
:host => host) | ||
end | ||
vms | ||
end | ||
|
||
################# | ||
# Relationships # | ||
################# | ||
|
||
let(:ems_rel) { ems.init_relationship } | ||
let(:cluster_rels) { clusters.map { |cluster| cluster.init_relationship(ems_rel) } } | ||
|
||
# The next to use a integer division trick to map the proper parent_rel to | ||
# the record being created (the `[index / child_per_parent]` part) | ||
|
||
let(:host_rels) do | ||
hosts.map.with_index do |host, index| | ||
host.init_relationship(cluster_rels[index / hosts_per_cluster]) | ||
end | ||
end | ||
|
||
let(:vm_rels) do | ||
vms.map.with_index do |vm, index| | ||
vm.init_relationship(host_rels[index / vms_per_host]) | ||
end | ||
end | ||
|
||
########### | ||
# Helpers # | ||
########### | ||
|
||
# Convenience statement for initializing the tree (there is no included | ||
# `before` to do this automatically | ||
let(:init_full_tree) { vm_rels } | ||
end |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi: https://apidock.com/rails/ActiveSupport/CoreExtensions/Array/ExtractOptions/extract_options%21
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was aware of this, but I was avoiding it since down the chain it is also called in
fulltree_rels_arranged
. Instead of changing pulling out theoptions
here, I was being explicit and only removing the single key I needed here. Seemed less risky to not mutate args here when it was already being done later infulltree_rels_arranged
.That said, I am not terribly partial to this line of thought here. I guess the diff for doing this would then look like this:
Does make that last line a bit longer, and I am all about shorter lines when possible, but should be the same.