ObinnaIheanachor commented on code in PR #62160:
URL: https://github.com/apache/airflow/pull/62160#discussion_r2833030560


##########
airflow-core/src/airflow/api_fastapi/common/db/dag_runs.py:
##########
@@ -52,3 +52,18 @@ def eager_load_dag_run_for_validation() -> 
tuple[LoaderOption, ...]:
         .joinedload(DagVersion.bundle),
         joinedload(DagRun.dag_run_note),
     )
+
+
+def eager_load_dag_run_for_list() -> tuple[LoaderOption, ...]:
+    """
+    Eager loading options for listing DagRuns.
+
+    IMPORTANT: Do NOT load task instances / histories here.
+    Those collections can be huge and will cause extra queries and/or row 
explosion,
+    which makes list endpoints slow on large installations.
+    """
+    return (
+        joinedload(DagRun.dag_model),
+        joinedload(DagRun.dag_run_note),
+        joinedload(DagRun.created_dag_version).joinedload(DagVersion.bundle),

Review Comment:
   I've reworked the fix so DAGRunResponse semantics remain unchanged.
   List endpoints now use a dedicated response model to avoid accessing 
DagRun.dag_versions during serialization (the source of the N+1).
   Also explicitly eager-loading DagVersion.dag_model to prevent implicit lazy 
loads.



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