Skip to content

Commit

Permalink
Load Lans effeciently in MiqProvisionVirtWorkflow
Browse files Browse the repository at this point in the history
Instead of preloading Lan records, splitting them up based on if they are
shareable and instantiating entire ActiveRecord to only use the name
column in a hash, use a specific query to gather and filter those values
and generate a hash from that.
  • Loading branch information
NickLaMuro committed May 3, 2018
1 parent c2e01c9 commit 6257d58
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/models/miq_provision_virt_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ def available_vlans_and_hosts(options = {})
hosts = get_selected_hosts(src)
unless @vlan_options[:vlans] == false
rails_logger('allowed_vlans', 0)
# TODO: Use Active Record to preload this data?
MiqPreloader.preload(hosts, :lans => :switches)
load_allowed_vlans(hosts, vlans)
rails_logger('allowed_vlans', 1)
end
Expand All @@ -244,9 +242,11 @@ def load_allowed_vlans(hosts, vlans)
end

def load_hosts_vlans(hosts, vlans)
hosts.each do |h|
h.lans.each { |l| vlans[l.name] = l.name unless l.switch.shared? }
end
Lan.joins(:switch => :hosts)
.where(:hosts => {:id => hosts.map(&:id)})
.where(:switches => {:shared => [nil, false]})
.distinct.pluck(:name)
.each_with_object(vlans) { |v, h| h[v] = v }
end

def filter_by_tags(target, options)
Expand Down

0 comments on commit 6257d58

Please sign in to comment.