Skip to content

Commit

Permalink
Merge pull request #17325 from NickLaMuro/flatten_arranged_rels_optim…
Browse files Browse the repository at this point in the history
…ization

Remove N+1 obj creation in flatten_arranged_rels
(cherry picked from commit 32fadeb)

https://bugzilla.redhat.com/show_bug.cgi?id=1593798
  • Loading branch information
kbrock authored and simaishi committed Jun 21, 2018
1 parent ef6b3f9 commit a6dc75e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/models/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,15 @@ def resource_pair
#

def self.flatten_arranged_rels(relationships)
relationships.each_with_object([]) do |(rel, children), a|
a << rel
a.concat(flatten_arranged_rels(children))
result = relationships.keys
remaining_children = relationships.values
until remaining_children.empty?
remaining_children.pop.each do |rel, kids|
result << rel
remaining_children << kids
end
end
result
end

def self.arranged_rels_to_resources(relationships, initial = true)
Expand Down

0 comments on commit a6dc75e

Please sign in to comment.