Skip to content

Commit

Permalink
Fixes #5946 - Only call fact_name_class.maximum if necessary.
Browse files Browse the repository at this point in the history
  • Loading branch information
nbarrientos authored and dLobatog committed May 27, 2014
1 parent 51702d6 commit 9e78711
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions app/services/fact_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ def delete_removed_facts
end

def add_new_facts
fact_names = fact_name_class.maximum(:id, :group => 'name')
facts_to_create = facts.keys - db_facts.keys
# if the host does not exists yet, we don't have an host_id to use the fact_values table.
method = host.new_record? ? :build : :create!
facts_to_create.each do |name|
host.fact_values.send(method, :value => facts[name],
:fact_name_id => fact_names[name] || fact_name_class.create!(:name => name).id)
if facts_to_create.present?
method = host.new_record? ? :build : :create!
fact_names = fact_name_class.maximum(:id, :group => 'name')
facts_to_create.each do |name|
host.fact_values.send(method, :value => facts[name],
:fact_name_id => fact_names[name] || fact_name_class.create!(:name => name).id)
end
end

@counters[:added] = facts_to_create.size
Expand Down

0 comments on commit 9e78711

Please sign in to comment.