Project

General

Profile

« Previous | Next » 

Revision 20cc5f65

Added by Tom Caspy over 8 years ago

fixes #11610 - removing a bunch of N+1 queries from the migration

View differences:

db/migrate/20150819105725_add_lookup_value_match_to_host_and_hostgroup.rb
Host::Managed.reset_column_information
Hostgroup.reset_column_information
Host::Managed.where(:type => 'Host::Managed').find_in_batches(:batch_size => 100) do |group|
group.each do |host|
host.update_attribute(:lookup_value_matcher, host.send(:lookup_value_match))
end
matchers = LookupValue.where("lookup_values.match like ?", "fqdn=%").uniq.pluck('lookup_values.match')
fqdns = matchers.map{|m| m.gsub(/^fqdn=/, "")}
hostnames = fqdns.map{|fqdn| fqdn.split(".").first}
if SETTINGS[:unattended]
hosts = Host::Managed.where(:nics => {:name => (fqdns + hostnames)}).joins(:primary_interface)
else
fact_name_id = FactName.where(:name => "fqdn").first.id
hosts = Host::Managed.joins(:fact_values).where(:fact_values => {:fact_name_id => fact_name_id, :value => (fqdns + hostnames)})
end
hosts = hosts.readonly(false).uniq
hosts.each do |host|
host.update_attribute(:lookup_value_matcher, host.send(:lookup_value_match))
end
Hostgroup.find_in_batches(:batch_size => 100) do |group|

Also available in: Unified diff