You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "uranusjr (via GitHub)" <gi...@apache.org> on 2023/06/13 10:08:00 UTC

[GitHub] [airflow] uranusjr commented on a diff in pull request #30911: Save DAG parsing time if dag is not scheduleable

uranusjr commented on code in PR #30911:
URL: https://github.com/apache/airflow/pull/30911#discussion_r1227874336


##########
airflow/models/dag.py:
##########
@@ -2884,25 +2884,28 @@ def bulk_write_to_db(
             session.add(orm_dag)
             orm_dags.append(orm_dag)
 
-        # Get the latest dag run for each existing dag as a single query (avoid n+1 query)
-        most_recent_subq = (
-            session.query(DagRun.dag_id, func.max(DagRun.execution_date).label("max_execution_date"))
-            .filter(
-                DagRun.dag_id.in_(existing_dags),
-                or_(DagRun.run_type == DagRunType.BACKFILL_JOB, DagRun.run_type == DagRunType.SCHEDULED),
+        most_recent_runs = {}
+        num_active_runs = {}
+        # Save runtime if dag is not scheduleable
+        if any([dag.timetable.can_be_scheduled for dag in dags]):

Review Comment:
   ```suggestion
           if any(dag.timetable.can_be_scheduled for dag in dags):
   ```



##########
airflow/models/dag.py:
##########
@@ -2884,25 +2884,28 @@ def bulk_write_to_db(
             session.add(orm_dag)
             orm_dags.append(orm_dag)
 
-        # Get the latest dag run for each existing dag as a single query (avoid n+1 query)
-        most_recent_subq = (
-            session.query(DagRun.dag_id, func.max(DagRun.execution_date).label("max_execution_date"))
-            .filter(
-                DagRun.dag_id.in_(existing_dags),
-                or_(DagRun.run_type == DagRunType.BACKFILL_JOB, DagRun.run_type == DagRunType.SCHEDULED),
+        most_recent_runs = {}
+        num_active_runs = {}

Review Comment:
   From past experience, Mypy will probably ask you to provide better type hints for these. Instead of having an empty dict here, it’s generally easier to add an else block.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org