shubhamraj-git commented on code in PR #44701:
URL: https://github.com/apache/airflow/pull/44701#discussion_r1878624389


##########
airflow/api_fastapi/core_api/routes/ui/structure.py:
##########
@@ -63,4 +63,31 @@ def structure_data(
         "edges": edges,
     }
 
+    if external_dependencies:
+        entry_node_ref = nodes[0]

Review Comment:
   Should we check for nodes or edges are empty?



##########
airflow/api_fastapi/core_api/routes/ui/structure.py:
##########
@@ -63,4 +63,31 @@ def structure_data(
         "edges": edges,
     }
 
+    if external_dependencies:
+        entry_node_ref = nodes[0]
+        exit_node_ref = nodes[-1]
+
+        for dependency_dag_id, dependencies in 
SerializedDagModel.get_dag_dependencies().items():
+            for dependency in dependencies:
+                if dependency_dag_id != dag_id and dependency.target != dag_id:
+                    continue
+
+                # Add nodes
+                nodes.append(
+                    {
+                        "id": dependency.node_id,
+                        "label": dependency.node_id,
+                        "type": dependency.dependency_type,
+                    }
+                )
+
+                # Add edges
+                # start dependency
+                if dependency.target != dependency.dependency_type:
+                    edges.insert(0, {"source_id": dependency.node_id, 
"target_id": entry_node_ref["id"]})

Review Comment:
   This operation shifts all elements in the list, might be expensive.
   Can we optimise it to something like
   
   ```
   start_edges = []
   end_edges = []
   
   for....
       .....
       # Collect start and end edges
           if dependency.target != dependency.dependency_type:
               # Start dependency
               start_edges.append({"source_id": dependency.node_id, 
"target_id": entry_node_ref["id"]})
           elif dependency.source != dependency.dependency_type:
               # End dependency
               end_edges.append({"source_id": exit_node_ref["id"], "target_id": 
dependency.node_id})
   
   edges = start_edges + edges + end_edges
   
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to