ephraimbuddy commented on code in PR #62062:
URL: https://github.com/apache/airflow/pull/62062#discussion_r2816457937
##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -241,12 +241,18 @@ def ti_run(
xcom_query = xcom_query.where(XComModel.map_index == map_index)
xcom_keys = list(session.scalars(xcom_query))
- task_reschedule_count = (
- session.scalar(
-
select(func.count(TaskReschedule.id)).where(TaskReschedule.ti_id ==
task_instance_id)
+
+ has_reschedules =
session.scalar(select(exists().where(TaskReschedule.ti_id == task_instance_id)))
+
+ if has_reschedules:
+ task_reschedule_count = (
+ session.scalar(
+
select(func.count(TaskReschedule.id)).where(TaskReschedule.ti_id ==
task_instance_id)
+ )
+ or 0
Review Comment:
This amounts to double queries. I think the right fix is adding index on the
id which was done here: https://github.com/apache/airflow/pull/61983
--
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]