pierrejeambrun commented on code in PR #57450:
URL: https://github.com/apache/airflow/pull/57450#discussion_r2481898659
##########
airflow-core/src/airflow/api_fastapi/common/db/dag_runs.py:
##########
@@ -33,3 +38,16 @@
.group_by(DagRun.dag_id, DagRun.state, DagModel.dag_display_name)
.order_by(DagRun.dag_id)
)
+
+
+def eager_load_dag_run_for_validation() -> tuple[LoaderOption, ...]:
+ return (
+ joinedload(DagRun.dag_model),
+ selectinload(DagRun.task_instances)
+ .joinedload(TaskInstance.dag_version)
+ .joinedload(DagVersion.bundle),
+ selectinload(DagRun.task_instances_histories)
+ .joinedload(TaskInstanceHistory.dag_version)
+ .joinedload(DagVersion.bundle),
+ joinedload(DagRun.dag_run_note),
+ )
Review Comment:
> yeah so, i looked at one usage, get_list_dag_runs_batch, and it doesn't
need anything from TI or TIH -- so it would be hitting those tables
unnecessarily. Probably true of others as well.
You missed the `dag_versions` property from the dag_run. This go trough both
TI and TIH association proxy to load the related dag version, so we do need
that.
##########
airflow-core/src/airflow/api_fastapi/common/db/dag_runs.py:
##########
@@ -33,3 +38,16 @@
.group_by(DagRun.dag_id, DagRun.state, DagModel.dag_display_name)
.order_by(DagRun.dag_id)
)
+
+
+def eager_load_dag_run_for_validation() -> tuple[LoaderOption, ...]:
+ return (
+ joinedload(DagRun.dag_model),
+ selectinload(DagRun.task_instances)
+ .joinedload(TaskInstance.dag_version)
+ .joinedload(DagVersion.bundle),
+ selectinload(DagRun.task_instances_histories)
+ .joinedload(TaskInstanceHistory.dag_version)
+ .joinedload(DagVersion.bundle),
+ joinedload(DagRun.dag_run_note),
+ )
Review Comment:
> yeah so, i looked at one usage, get_list_dag_runs_batch, and it doesn't
need anything from TI or TIH -- so it would be hitting those tables
unnecessarily. Probably true of others as well.
You missed the `dag_versions` property from the dag_run. This go trough both
TI and TIH association proxy to load the related dag version, we do need to
preload them.
--
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]