kaxil commented on a change in pull request #9850:
URL: https://github.com/apache/airflow/pull/9850#discussion_r455714688



##########
File path: airflow/models/serialized_dag.py
##########
@@ -94,13 +97,26 @@ def write_dag(cls, dag: DAG, min_update_interval: 
Optional[int] = None, session=
                      (timezone.utcnow() - 
timedelta(seconds=min_update_interval)) < cls.last_updated))
             ).scalar():
                 return
-        log.debug("Writing DAG: %s to the DB", dag.dag_id)
-        session.merge(cls(dag))
+
+        log.debug("Checking if DAG (%s) is updated or same", dag.dag_id)
+        serialized_dag_from_db: SerializedDagModel = (
+            session
+            .query(cls)
+            .filter(cls.dag_id == dag.dag_id)
+            .one_or_none()
+        )

Review comment:
       `get` will only provide performance boost if the object is in memory 
isn't it?
   
   Otherwise under the hood, get calls `one`  which in turn calls `one_or_none`:
   
   
https://github.com/sqlalchemy/sqlalchemy/blob/f4aa9def8f35136d1fe3bba81aaeddb72e7772a2/lib/sqlalchemy/orm/query.py#L907
   
   
https://github.com/sqlalchemy/sqlalchemy/blob/rel_1_3_17/lib/sqlalchemy/orm/loading.py#L287
   
   
https://github.com/sqlalchemy/sqlalchemy/blob/f4aa9def8f35136d1fe3bba81aaeddb72e7772a2/lib/sqlalchemy/orm/query.py#L2641-L2659
   
   




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to