Copilot commented on code in PR #61273:
URL: https://github.com/apache/airflow/pull/61273#discussion_r2748482989
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/grid.py:
##########
@@ -176,12 +178,22 @@ def get_dag_structure(
nodes = [task_group_to_dict_grid(x) for x in
task_group_sort(latest_dag.task_group)]
return [GridNodeResponse(**n) for n in nodes]
- serdags = session.scalars(
- select(SerializedDagModel).where(
+ # Process and merge the latest serdag first
+ merged_nodes: list[dict[str, Any]] = []
+ nodes = [task_group_to_dict_grid(x) for x in
task_group_sort(latest_dag.task_group)]
+ _merge_node_dicts(merged_nodes, nodes)
+ del latest_dag
Review Comment:
Explicitly deleting `latest_dag` may not effectively free memory since the
DAG object could still be referenced elsewhere (e.g., within `merged_nodes`
through the task_group_to_dict_grid conversion). Consider removing this line as
the expunge operation on line 147 is the primary mechanism for memory
management, and explicit deletion provides no guaranteed benefit here.
```suggestion
```
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/grid.py:
##########
@@ -205,10 +217,11 @@ def get_dag_structure(
include_downstream=include_downstream,
depth=depth,
)
- dags.append(filtered_dag)
- for dag in dags:
- nodes = [task_group_to_dict_grid(x) for x in
task_group_sort(dag.task_group)]
- _merge_node_dicts(merged_nodes, nodes)
+ # Merge immediately instead of collecting all DAGs in memory
+ nodes = [task_group_to_dict_grid(x) for x in
task_group_sort(filtered_dag.task_group)]
+ _merge_node_dicts(merged_nodes, nodes)
Review Comment:
The variable `nodes` is created but not reused after merging. Consider
inlining the list comprehension directly into the `_merge_node_dicts` call to
avoid creating an intermediate list variable: `_merge_node_dicts(merged_nodes,
[task_group_to_dict_grid(x) for x in task_group_sort(filtered_dag.task_group)])`
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]