ObinnaIheanachor opened a new pull request, #62160:
URL: https://github.com/apache/airflow/pull/62160

   <!-- SPDX-License-Identifier: Apache-2.0 
https://www.apache.org/licenses/LICENSE-2.0 -->
   <!--
   Thank you for contributing!
   
   This PR fixes a performance regression in the FastAPI DagRun list endpoints 
reported in #62025 by avoiding unnecessary relationship loading and preventing 
N+1 queries during response serialization.
   
   **What changed**
        •       Introduced `eager_load_dag_run_for_list()` to define the 
minimal, safe eager-loading strategy for listing DagRuns:
                 - eagerly loads dag_model, dag_run_note, and 
created_dag_version (plus its bundle)
                 - explicitly avoids loading task_instances / 
task_instances_histories
        •       Updated /dags/{dag_id}/dagRuns and /dags/~/dagRuns/list to use 
eager_load_dag_run_for_list().
        •       Updated DAGRunResponse serialization to derive dag_versions 
from the already eagerly-loaded created_dag_version instead of touching 
DagRun.dag_versions (which is a DB-querying property), eliminating N+1 queries.
        •       Added/updated performance-focused tests to assert bounded query 
count and ensure list endpoints do not eager load TaskInstance collections.
   
   **Why**
   DagRun.dag_versions is implemented as a property that triggers DB access. 
When listing many DagRuns, serializing dag_versions caused extra queries and 
degraded performance. This PR ensures list endpoints remain bounded and do not 
accidentally load large collections.
   
   **Tests**
        •       pytest 
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_run.py
        •       pytest 
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_run_list_perf.py
   
   * closes: #62025 
   * related: #62027
   -->
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   <!--
   If generative AI tooling has been used in the process of authoring this PR, 
please
   change below checkbox to `[X]` followed by the name of the tool, uncomment 
the "Generated-by".
   -->
   
   - [ ] Yes (please specify the tool below)
   
   <!--
   Generated-by: [Tool Name] following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   -->
   
   ---
   
   * Read the **[Pull Request 
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
 for more information. Note: commit author/co-author name and email in commits 
become permanently public when merged.
   * For fundamental code changes, an Airflow Improvement Proposal 
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
 is needed.
   * When adding dependency, check compliance with the [ASF 3rd Party License 
Policy](https://www.apache.org/legal/resolved.html#category-x).
   * For significant user-facing changes create newsfragment: 
`{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in 
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
   


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