john-rodriguez-mgni commented on code in PR #61483:
URL: https://github.com/apache/airflow/pull/61483#discussion_r2775518011


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/dags.py:
##########
@@ -234,18 +234,22 @@ def get_dags(
             pending_actions_by_dag_id[dag_id].append(hitl_detail)
 
     # aggregate rows by dag_id
-    dag_runs_by_dag_id: dict[str, DAGWithLatestDagRunsResponse] = {
-        dag.dag_id: DAGWithLatestDagRunsResponse.model_validate(
-            {
-                **DAGResponse.model_validate(dag).model_dump(),
-                "asset_expression": dag.asset_expression,
-                "latest_dag_runs": [],
-                "pending_actions": pending_actions_by_dag_id[dag.dag_id],
-                "is_favorite": dag.dag_id in favorite_dag_ids,
-            }
+    # Performance optimization: Validate ORM to DAGResponse once per DAG, then 
use model_construct
+    # to build DAGWithLatestDagRunsResponse without redundant validation.
+    # The original pattern (model_validate -> model_dump -> model_validate) 
caused triple
+    # serialization overhead that scaled poorly with the number of DAGs.
+    dag_runs_by_dag_id: dict[str, DAGWithLatestDagRunsResponse] = {}
+    for dag in dags:
+        dag_response = DAGResponse.model_validate(dag)
+        dag_data = dag_response.model_dump()
+        dag_data["asset_expression"] = dag.asset_expression
+        dag_data["latest_dag_runs"] = []
+        dag_data["pending_actions"] = pending_actions_by_dag_id[dag.dag_id]
+        dag_data["is_favorite"] = dag.dag_id in favorite_dag_ids
+        dag_runs_by_dag_id[dag.dag_id] = 
DAGWithLatestDagRunsResponse.model_construct(

Review Comment:
   @tirkarthi let me know how this looks for you now.



-- 
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]

Reply via email to