diff --git a/app/models/ems_refresh/save_inventory_infra.rb b/app/models/ems_refresh/save_inventory_infra.rb index 30c15a6fd8d7..3b53d97250b4 100644 --- a/app/models/ems_refresh/save_inventory_infra.rb +++ b/app/models/ems_refresh/save_inventory_infra.rb @@ -64,7 +64,7 @@ def save_ems_infra_inventory(ems, hashes, target = nil, disconnect = true) :orchestration_templates, :orchestration_stacks ] - + old_switch_ids = ems.switches.pluck(:id) # Save and link other subsections save_child_inventory(ems, hashes, child_keys, target, disconnect) @@ -78,7 +78,7 @@ def save_ems_infra_inventory(ems, hashes, target = nil, disconnect = true) new_relats = hashes_relats(hashes) link_ems_inventory(ems, target, prev_relats, new_relats, disconnect) - remove_obsolete_switches + remove_obsolete_switches(old_switch_ids) ems end @@ -331,10 +331,11 @@ def save_switches_inventory(host, hashes) host.switches.delete(deletes) end - def remove_obsolete_switches + def remove_obsolete_switches(old_switch_ids) # delete from switches as s where s.shared is NULL and s.id not in (select switch_id from host_switches) # delete from switches as s where s.shared = 't' and s.id not in (select switch_id from host_switches) - Switch.where.not(:id => HostSwitch.all.collect(&:switch).uniq).destroy_all + obsolete_switch_ids = old_switch_ids - HostSwitch.all.collect(&:switch_id) + Switch.where(:id => obsolete_switch_ids).destroy_all end def save_lans_inventory(switch, hashes)