Skip to content

Commit

Permalink
add the flat graph back in with caching, PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Beck committed Jul 17, 2019
1 parent 1a4daab commit 6f5bf24
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/dbt/context/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ def generate_base(model, model_dict, config, manifest, source_config,
"exceptions": dbt.exceptions.wrapped_exports(model),
"execute": provider.execute,
"flags": dbt.flags,
"graph": manifest.to_flat_graph(),
"log": log,
"model": model_dict,
"modules": get_context_modules(),
Expand Down
14 changes: 14 additions & 0 deletions core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def __init__(self, nodes, macros, docs, generated_at, disabled,
self.generated_at = generated_at
self.metadata = metadata
self.disabled = disabled
self._flat_graph = None
super(Manifest, self).__init__()

@staticmethod
Expand Down Expand Up @@ -223,6 +224,19 @@ def serialize(self):
'disabled': [v.serialize() for v in self.disabled],
}

def to_flat_graph(self):
"""This function gets called in context.common by each node, so we want
to cache it. Make sure you don't call this until you're done with
building your manifest!
"""
if self._flat_graph is None:
self._flat_graph = {
'nodes': {
k: v.serialize() for k, v in self.nodes.items()
},
}
return self._flat_graph

def find_disabled_by_name(self, name, package=None):
return dbt.utils.find_in_list_by_name(self.disabled, name, package,
NodeType.refable())
Expand Down
4 changes: 4 additions & 0 deletions core/dbt/graph/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ def select(self, query):
selected = self.get_selected(include, exclude, resource_types, tags,
required)

# if you haven't selected any nodes, return that so we can give the
# nice "no models selected" message.
if not selected:
return selected
# we used to carefully go through all node ancestors and add those if
# they were ephemeral. Sadly, the algorithm we used ended up being
# O(n^2). Instead, since ephemeral nodes are almost free, just add all
Expand Down

0 comments on commit 6f5bf24

Please sign in to comment.