Revision 39004642
Added by Tomer Brisker over 2 years ago
app/services/fact_importer.rb | ||
---|---|---|
def update_facts
|
||
time = Time.now.utc
|
||
updated = 0
|
||
db_facts_names = []
|
||
db_facts = host.fact_values.joins(:fact_name).where(fact_names: {type: fact_name_class_name}).reorder(nil).pluck(:name, :value, :id)
|
||
db_facts.each do |name, value, id|
|
||
next unless fact_names.include?(name)
|
||
... | ... | |
FactValue.where(id: id).update_all(:value => new_value, :updated_at => time)
|
||
updated += 1
|
||
end
|
||
db_facts_names << name
|
||
end
|
||
db_facts_names = db_facts.map(&:first) & fact_names.keys
|
||
@facts_to_create = facts.keys - db_facts_names
|
||
@counters[:updated] = updated
|
||
end
|
Also available in: Unified diff
Refs #33639 - Reduce array resizing in fact importer
Instead of starting with an empty array and resizing it for every fact
added, we can calculate the final array right away.