Skip to content

Commit

Permalink
Improve performance of select_children() and select_parents()
Browse files Browse the repository at this point in the history
  • Loading branch information
peterallenwebb committed Dec 5, 2024
1 parent ff6745c commit 3a0e3fb
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions core/dbt/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,14 @@ def select_children(
while len(selected) > 0 and (max_depth is None or i < max_depth):
next_layer: Set[UniqueId] = set()
for node in selected:
next_layer.update(self.descendants(node, 1))
next_layer = next_layer - children # Avoid re-searching
next_layer.update(
iter(
e[1]
for e in self.graph.out_edges(node)
if e[1] not in children
and self.filter_edges_by_type(e[0], e[1], "parent_test")
)
)
children.update(next_layer)
selected = next_layer
i += 1
Expand All @@ -86,8 +92,14 @@ def select_parents(
while len(selected) > 0 and (max_depth is None or i < max_depth):
next_layer: Set[UniqueId] = set()
for node in selected:
next_layer.update(self.ancestors(node, 1))
next_layer = next_layer - parents # Avoid re-searching
next_layer.update(
iter(
e[0]
for e in self.graph.in_edges(node)
if e[0] not in parents
and self.filter_edges_by_type(e[0], e[1], "parent_test")
)
)
parents.update(next_layer)
selected = next_layer
i += 1
Expand Down

0 comments on commit 3a0e3fb

Please sign in to comment.