jason810496 commented on code in PR #55733:
URL: https://github.com/apache/airflow/pull/55733#discussion_r2353667555
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/dashboard.py:
##########
@@ -127,7 +127,20 @@ def dag_stats(
.subquery()
)
- latest_runs = (
+ # Active DAGs need another query from DagModel, as a DAG may not have any
runs but still be active
Review Comment:
```suggestion
# Active Dags need another query from DagModel, as a Dag may not have
any runs but still be active
```
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/dashboard.py:
##########
@@ -127,7 +127,20 @@ def dag_stats(
.subquery()
)
- latest_runs = (
+ # Active DAGs need another query from DagModel, as a DAG may not have any
runs but still be active
+ dags_cte = (
+ select(DagModel.dag_id, DagModel.is_paused)
+ .where(DagModel.is_stale == false())
+ .where(DagModel.dag_id.in_(permitted_dag_ids))
+ .cte()
+ )
+ active_count_query = select(
+ func.coalesce(func.sum(case((dags_cte.c.is_paused == false(), 1))),
0).label("active")
+ ).select_from(dags_cte)
+ active_count = session.execute(active_count_query).first().active
Review Comment:
Since the `dags_cte` isn't reused by further query, would it be better to
simplify the query as the following?
I just tested it locally and the result was correct.
```suggestion
active_count_query = (
select(func.count())
.select_from(DagModel)
.where(DagModel.is_stale == false())
.where(DagModel.is_paused == false())
.where(DagModel.dag_id.in_(permitted_dag_ids))
)
active_count = session.execute(active_count_query).scalar_one()
```
--
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]