ephraimbuddy commented on code in PR #63920:
URL: https://github.com/apache/airflow/pull/63920#discussion_r2973296545


##########
airflow-core/src/airflow/migrations/versions/0101_3_2_0_ui_improvements_for_deadlines.py:
##########
@@ -519,57 +644,124 @@ def _migrate_dag_deadlines(dag_conn: Connection) -> 
Iterable[str]:
                         )
 
                         if not validate_written_data(
-                            dag_conn, deadline_alert_id, reference_data, 
interval_data, callback_data
+                            dag_conn,
+                            deadline_alert_id,
+                            reference_data,
+                            interval_data,
+                            callback_data,
                         ):
                             dags_with_errors[dag_id].append(f"Invalid 
DeadlineAlert data: {serialized_alert}")
                             continue
 
                         yield deadline_alert_id
-                        dag_conn.execute(
-                            sa.text("""
-                                UPDATE deadline
-                                SET deadline_alert_id = :alert_id
-                                WHERE dagrun_id IN (
+                        # Fetch dagrun IDs once per DAG to avoid repeating the
+                        # expensive dag_run/serialized_dag JOIN for every 
alert.
+                        dagrun_ids = [

Review Comment:
   The comment here "Fetch dagrun IDs once per DAG" is different from what's 
implemented below. `serialized_dag_id ` is constant for the whole DAG, so 
`dagrun_ids` is the same for every alert. You can move this query outside the 
`for serialized_alert ` loop (e.g. once at the start of 
`_migrate_dag_deadlines`) and reuse `dagrun_ids ` for all alerts in the same 
DAG. Would make things faster too



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