Skip to content

Commit

Permalink
Merge pull request ManageIQ#15636 from Ladas/sort_nodes_for_a_proper_…
Browse files Browse the repository at this point in the history
…disconnect_destroy_order

Sort nodes for a proper disconnect_inv/destroy order
  • Loading branch information
agrare authored Jul 28, 2017
2 parents 3c599e9 + 0279221 commit fe1f825
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/models/manager_refresh/inventory_collection/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,21 @@ def build_directed_acyclic_graph!
# depth 10. We should throw a warning maybe asking for simplifying the interconnections in the models.
assert_graph!(edges)

self.nodes = sort_nodes(nodes)

self
end

private

def sort_nodes(nodes)
# Separate to root nodes and child nodes, where child nodes are determined by having parent_inventory_collections
root_nodes, child_nodes = nodes.partition { |node| node.parent_inventory_collections.blank? }
# And order it that root nodes comes first, that way the disconnect of the child nodes should be always done as
# a part of the root nodes, as intended.
root_nodes + child_nodes
end

def assert_inventory_collections(inventory_collections)
inventory_collections.each do |inventory_collection|
unless inventory_collection.kind_of? ::ManagerRefresh::InventoryCollection
Expand Down

0 comments on commit fe1f825

Please sign in to comment.