Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize pruning #3

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions core/dbt/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down