dstandish commented on code in PR #50984:
URL: https://github.com/apache/airflow/pull/50984#discussion_r2110437104


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -115,30 +116,54 @@ def get_dags(
     session: SessionDep,
 ) -> DAGCollectionResponse:
     """Get all DAGs."""
-    dag_runs_select = None
+    query = select(DagModel)
 
-    if dag_run_state.value or dag_run_start_date_range.is_active() or 
dag_run_end_date_range.is_active():
-        dag_runs_select, _ = paginated_select(
-            statement=select(DagRun),
+    max_run_id_query = (  # ordering by id will not always be "latest run", 
but it's a simplifying assumption
+        select(DagRun.dag_id, func.max(DagRun.id).label("max_dag_run_id"))

Review Comment:
   So, this is the query for getting the latest dag run by start_date
   ```
   SELECT
       dag.dag_display_name,
       dag.dag_id,
       dag.is_paused,
       dag.is_stale,
       dag.last_parsed_time,
       dag.last_expired,
       dag.fileloc,
       dag.relative_fileloc,
       dag.bundle_name,
       dag.bundle_version,
       dag.owners,
       dag.description,
       dag.timetable_summary,
       dag.timetable_description,
       dag.asset_expression,
       dag.deadline,
       dag.max_active_tasks,
       dag.max_active_runs,
       dag.max_consecutive_failed_dag_runs,
       dag.has_task_concurrency_limits,
       dag.has_import_errors,
       dag.next_dagrun,
       dag.next_dagrun_data_interval_start,
       dag.next_dagrun_data_interval_end,
       dag.next_dagrun_create_after
   FROM
       dag
       LEFT OUTER JOIN (SELECT
                            mrq_inner.dag_id AS dag_id,
                            mrq_inner.max_run_id AS max_run_id
                        FROM
                            (SELECT
                                 dag_run.id AS max_run_id,
                                 dag_run.dag_id AS dag_id,
                                     row_number() OVER (PARTITION BY 
dag_run.dag_id ORDER BY dag_run.start_date DESC) AS rn
                             FROM dag_run
                             WHERE
                                 dag_run.start_date IS NOT NULL
                            ) AS mrq_inner
                        WHERE
                            mrq_inner.rn = 1
       ) AS mrq ON dag.dag_id = mrq.dag_id
       LEFT OUTER JOIN dag_run ON dag_run.id = mrq.max_run_id
   ```
   We could do it but, not sure how well it will perform



-- 
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]

Reply via email to