From 138e11263ddd2199c7a912a201e77b9d90a08b33 Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Tue, 12 Jun 2018 13:14:31 +0200 Subject: [PATCH] Skip Vm reconnect if already reconnected Applied changes from PR 17417 --- .../manager_refresh/inventory_collection/builder/shared.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/manager_refresh/inventory_collection/builder/shared.rb b/app/models/manager_refresh/inventory_collection/builder/shared.rb index 9678cb25383..93298b214cd 100644 --- a/app/models/manager_refresh/inventory_collection/builder/shared.rb +++ b/app/models/manager_refresh/inventory_collection/builder/shared.rb @@ -9,7 +9,7 @@ module ManagerRefresh::InventoryCollection::Builder::Shared inventory_objects_index.each_slice(100) do |batch| batch_refs = batch.map(&:first) - relation.where(inventory_collection.manager_ref.first => batch_refs).each do |record| + relation.where(inventory_collection.manager_ref.first => batch_refs).order(:id => :asc).each do |record| index = inventory_collection.object_index_with_keys(inventory_collection.manager_ref_to_cols, record) # We need to delete the record from the inventory_objects_index @@ -17,6 +17,9 @@ module ManagerRefresh::InventoryCollection::Builder::Shared inventory_object = inventory_objects_index.delete(index) hash = attributes_index.delete(index) + # Skip if hash is blank, which can happen when having several archived entities with the same ref + next unless hash + record.assign_attributes(hash.except(:id, :type)) if !inventory_collection.check_changed? || record.changed? record.save!