Eason09053360 opened a new pull request, #73033: URL: https://github.com/apache/airflow/pull/73033
## Why `airflow dags list` issued two extra queries for every Dag it printed. `get_dag_detail` is passed to `AirflowConsole.print_as` as the row mapper, so it runs once per Dag, and each call did a `DagModel.get_dagmodel()` lookup plus a lazy load of `DagModel.tags` when `DAGResponse` serialised the row. The command therefore cost `2N` round trips on a deployment with `N` Dags — measured at 24 queries for 2 Dags and 32 for 6, i.e. exactly two per Dag — which is worst on the installations where listing Dags is least convenient to do any other way. ## What `dag_list_dags` in `airflow-core/src/airflow/cli/commands/dag_command.py` now materialises the sorted, bundle-filtered Dag list first and prefetches the matching `DagModel` rows into a dict keyed by `dag_id`, with `selectinload(DagModel.tags)` covering the second lazy load. The mapper reads from that dict; the dagbag fallback for Dags absent from the `dag` table is unchanged, and so is the command's output. The prefetch is chunked at 500 ids using the `chunks()` helper already used in this file for `_RUN_CHUNK_SIZE`. A single unchunked `IN` would exceed the backend bind parameter cap (SQLite 32766, PostgreSQL 65535) and fail outright on very large installations, which the per-Dag lookup never did. Two tests in `airflow-core/tests/unit/cli/commands/test_dag_command.py`: `test_cli_list_dags_does_not_query_per_dag` asserts the query count is the same for 2 and 6 Dags, and `test_cli_list_dags_lists_every_dag_when_lookup_is_chunked` patches the chunk size to 2 and checks every Dag still comes back with a non-null `is_paused` — a column only the prefetched `DagModel` can supply, so it fails if chunking drops rows. -- 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]
