@@ -530,6 +530,22 @@ impl QueryGraph {
530530 . map ( |edge| NodeRef { node_ix : edge. source ( ) } )
531531 }
532532
533+ fn outgoing_projected_data_dependencies ( & self , node : & NodeRef ) -> impl Iterator < Item = & FieldSelection > {
534+ self . graph
535+ . edges_directed ( node. node_ix , Direction :: Outgoing )
536+ . filter_map ( |edge| match edge. weight ( ) . borrow ( ) {
537+ Some ( QueryGraphDependency :: ProjectedDataDependency ( requested_selection, _, _) ) => Some ( requested_selection) ,
538+ _ => None ,
539+ } )
540+ }
541+
542+ fn incoming_projected_data_dependency_edge ( & self , node : & NodeRef ) -> Option < EdgeRef > {
543+ self . graph
544+ . edges_directed ( node. node_ix , Direction :: Incoming )
545+ . find ( |edge| matches ! ( edge. weight( ) . borrow( ) , Some ( QueryGraphDependency :: ProjectedDataDependency ( _, _, _) ) ) )
546+ . map ( |edge| EdgeRef { edge_ix : edge. id ( ) } )
547+ }
548+
533549 /// Removes the edge from the graph but leaves the graph intact by keeping the empty
534550 /// edge in the graph by plucking the content of the edge, but not the edge itself.
535551 /// Panics if the edge has been already been taken or plucked.
@@ -846,26 +862,12 @@ impl QueryGraph {
846862 . collect ( ) ;
847863
848864 for return_node in return_nodes {
849- let out_edges = self . outgoing_edges ( & return_node) ;
850- let dependencies = FieldSelection :: union_iter ( out_edges. into_iter ( ) . filter_map ( |edge| {
851- if let QueryGraphDependency :: ProjectedDataDependency ( requested_selection, _, _) =
852- self . edge_content ( & edge) . unwrap ( )
853- {
854- Some ( requested_selection. clone ( ) )
855- } else {
856- None
857- }
858- } ) ) ;
865+ let dependencies =
866+ FieldSelection :: union_iter ( self . outgoing_projected_data_dependencies ( & return_node) . cloned ( ) ) ;
859867
860868 // Assumption: We currently always have at most one single incoming ProjectedDataDependency edge
861869 // connected to return nodes. This will break if we ever have more.
862- let in_edges = self . incoming_edges ( & return_node) ;
863- let incoming_dep_edge = in_edges. into_iter ( ) . find ( |edge| {
864- matches ! (
865- self . edge_content( edge) ,
866- Some ( QueryGraphDependency :: ProjectedDataDependency ( _, _, _) )
867- )
868- } ) ;
870+ let incoming_dep_edge = self . incoming_projected_data_dependency_edge ( & return_node) ;
869871
870872 if let Some ( incoming_edge) = incoming_dep_edge {
871873 let source = self . edge_source ( & incoming_edge) ;
@@ -1085,18 +1087,10 @@ impl QueryGraph {
10851087 let node = NodeRef { node_ix : ix } ;
10861088
10871089 if let Node :: Query ( q) = self . node_content ( & node) . unwrap ( ) {
1088- let edges = self . outgoing_edges ( & node) ;
1089- let mut unsatisfied_dependencies =
1090- edges
1091- . into_iter ( )
1092- . filter_map ( |edge| match self . edge_content ( & edge) . unwrap ( ) {
1093- QueryGraphDependency :: ProjectedDataDependency ( requested_selection, _, _)
1094- if !q. satisfies ( requested_selection) =>
1095- {
1096- Some ( requested_selection. clone ( ) )
1097- }
1098- _ => None ,
1099- } ) ;
1090+ let mut unsatisfied_dependencies = self
1091+ . outgoing_projected_data_dependencies ( & node)
1092+ . filter ( |requested_selection| !q. satisfies ( requested_selection) )
1093+ . cloned ( ) ;
11001094
11011095 let first = unsatisfied_dependencies. next ( ) ?;
11021096 Some ( (
0 commit comments