From cc72c78d0310f76ee6740c82a3e3a4d6808e276a Mon Sep 17 00:00:00 2001 From: Tobie Tusing Date: Fri, 7 Apr 2023 19:09:34 -0700 Subject: [PATCH] optimize pruning --- core/dbt/graph/graph.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/dbt/graph/graph.py b/core/dbt/graph/graph.py index 29f24cae734..62a5e89ba97 100644 --- a/core/dbt/graph/graph.py +++ b/core/dbt/graph/graph.py @@ -75,16 +75,21 @@ def get_subset_graph(self, selected: Iterable[UniqueId]) -> "Graph": include_nodes = set(selected) still_removing = True + node_superset = set(new_graph.nodes()) while still_removing: - nodes_to_remove = list( + nodes_to_remove = set( node - for node in new_graph + for node in node_superset if node not in include_nodes - and (new_graph.in_degree(node) * new_graph.out_degree(node)) == 0 + and (new_graph.in_degree(node) == 0 or new_graph.out_degree(node) == 0) ) if len(nodes_to_remove) == 0: still_removing = False else: + # set node_superset to the nodes that are neighbors of nodes_to_remove + node_superset = set( + new_graph.predecessors(nodes_to_remove) | new_graph.successors(nodes_to_remove) + ) new_graph.remove_nodes_from(nodes_to_remove) # sort remaining nodes by degree