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

feat(query): adding indirect and all dependencies for tasks #9207

Merged
merged 8 commits into from
Oct 11, 2024

Conversation

NicholasLYang
Copy link
Contributor

@NicholasLYang NicholasLYang commented Oct 1, 2024

Description

Adds indirect and all dependencies as fields on tasks.

You can review commit by commit.

Testing Instructions

Adds tests along with a new fixture based off of task-dependencies/complex

Copy link

vercel bot commented Oct 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
examples-nonmonorepo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 11, 2024 3:26pm
8 Skipped Deployments
Name Status Preview Comments Updated (UTC)
examples-basic-web ⬜️ Ignored (Inspect) Visit Preview Oct 11, 2024 3:26pm
examples-designsystem-docs ⬜️ Ignored (Inspect) Visit Preview Oct 11, 2024 3:26pm
examples-gatsby-web ⬜️ Ignored (Inspect) Visit Preview Oct 11, 2024 3:26pm
examples-kitchensink-blog ⬜️ Ignored (Inspect) Visit Preview Oct 11, 2024 3:26pm
examples-native-web ⬜️ Ignored (Inspect) Visit Preview Oct 11, 2024 3:26pm
examples-svelte-web ⬜️ Ignored (Inspect) Visit Preview Oct 11, 2024 3:26pm
examples-tailwind-web ⬜️ Ignored (Inspect) Visit Preview Oct 11, 2024 3:26pm
examples-vite-web ⬜️ Ignored (Inspect) Visit Preview Oct 11, 2024 3:26pm

Copy link
Contributor Author

NicholasLYang commented Oct 1, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @NicholasLYang and the rest of your teammates on Graphite Graphite

@NicholasLYang NicholasLYang changed the title Factoring out transitive closure to graph-utils feat(query): adding indirect and all dependencies for tasks Oct 1, 2024
@NicholasLYang NicholasLYang force-pushed the nicholasyang/add-indirect-task-dependencies branch from c0e5833 to c1242c8 Compare October 1, 2024 19:48
@NicholasLYang NicholasLYang force-pushed the nicholasyang/add-task-dependencies branch from adb85f8 to ea55c51 Compare October 8, 2024 18:39
Base automatically changed from nicholasyang/add-task-dependencies to main October 8, 2024 19:13
@NicholasLYang NicholasLYang force-pushed the nicholasyang/add-indirect-task-dependencies branch from c1242c8 to 60d2f51 Compare October 8, 2024 19:31
@NicholasLYang NicholasLYang marked this pull request as ready for review October 8, 2024 19:33
@NicholasLYang NicholasLYang requested a review from a team as a code owner October 8, 2024 19:33
Copy link
Member

@tknickman tknickman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Member

@chris-olszewski chris-olszewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good, minor suggestion that makes transitive_closure easier for me to understand.

Comment on lines 24 to 39
pub fn transitive_closure<
'a,
'b,
N: Hash + Eq + PartialEq + Clone + 'b,
M: TryFrom<N> + Hash + Eq + PartialEq,
I: IntoIterator<Item = &'b N>,
>(
graph: &'a Graph<N, ()>,
node_lookup: &'a HashMap<M, petgraph::graph::NodeIndex>,
nodes: I,
direction: petgraph::Direction,
) -> HashSet<&'a N> {
let indices = nodes
.into_iter()
.filter_map(|node| node_lookup.get(&node.to_owned().try_into().ok()?))
.copied();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having callers resolve the nodes to indices themselves makes this a lot more legible and easier to call in a lot of cases

Suggested change
pub fn transitive_closure<
'a,
'b,
N: Hash + Eq + PartialEq + Clone + 'b,
M: TryFrom<N> + Hash + Eq + PartialEq,
I: IntoIterator<Item = &'b N>,
>(
graph: &'a Graph<N, ()>,
node_lookup: &'a HashMap<M, petgraph::graph::NodeIndex>,
nodes: I,
direction: petgraph::Direction,
) -> HashSet<&'a N> {
let indices = nodes
.into_iter()
.filter_map(|node| node_lookup.get(&node.to_owned().try_into().ok()?))
.copied();
pub fn transitive_closure<
N: Hash + Eq + PartialEq,
I: IntoIterator<Item = NodeIndex>,
>(
graph: &Graph<N, ()>,
indicies: I,
direction: petgraph::Direction,
) -> HashSet<&N> {

A majority of the calls go from something like

        let mut dependencies = turborepo_graph_utils::transitive_closure(
            self.transitive_closure_inner(Some(node), petgraph::Direction::Outgoing);
            &self.graph,
            &self.node_lookup,
            Some(node),
            petgraph::Direction::Outgoing,
        );

to

        let mut dependencies = turborepo_graph_utils::transitive_closure(
            self.transitive_closure_inner(Some(node), petgraph::Direction::Outgoing);
            &self.graph,
            self.node_lookup.get(node).copied(),
            petgraph::Direction::Outgoing,
        );

@NicholasLYang NicholasLYang merged commit a99773e into main Oct 11, 2024
41 checks passed
@NicholasLYang NicholasLYang deleted the nicholasyang/add-indirect-task-dependencies branch October 11, 2024 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants