diff --git a/app/models/miq_provision_virt_workflow.rb b/app/models/miq_provision_virt_workflow.rb index ae9643595e18..068056e79bc8 100644 --- a/app/models/miq_provision_virt_workflow.rb +++ b/app/models/miq_provision_virt_workflow.rb @@ -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 @@ -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)