ricky-chaoju commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2700649049
##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -2432,19 +2432,23 @@ def _get_num_times_stuck_in_queued(self, ti:
TaskInstance, session: Session = NE
.limit(1)
)
- query = session.query(Log).where(
- Log.task_id == ti.task_id,
- Log.dag_id == ti.dag_id,
- Log.run_id == ti.run_id,
- Log.map_index == ti.map_index,
- Log.try_number == ti.try_number,
- Log.event == TASK_STUCK_IN_QUEUED_RESCHEDULE_EVENT,
+ statement = (
+ select(func.count())
+ .select_from(Log)
Review Comment:
I think `func.count()` is the right approach here since we need to count
matching rows. The query above (`select(Log.dttm)`) fetches a datetime value,
which has a different purpose. Using `func.count()` performs the counting in
the database efficiently, whereas alternatives like
`len(session.scalars(...).all())` would fetch all rows to Python first.
--
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]