ashb commented on code in PR #22917:
URL: https://github.com/apache/airflow/pull/22917#discussion_r848476163


##########
airflow/models/serialized_dag.py:
##########
@@ -220,6 +220,36 @@ def remove_dag(cls, dag_id: str, session: Session = None):
         """
         session.execute(cls.__table__.delete().where(cls.dag_id == dag_id))
 
+    @classmethod
+    @provide_session
+    def remove_unknown_dags_in_dag_file(
+        cls, active_dag_ids: List[str], dag_file_path: str, session=None
+    ) -> List[str]:
+        """
+        Deletes serialized_dags whose dag_ids are not in the active_dag_ids 
for a given dag_file_path
+
+        :return: a list of inactive dag ids
+        :rtype: list[str]
+        """
+        file_path_hash = DagCode.dag_fileloc_hash(dag_file_path)
+        # there is a db index on fileloc_hash
+        rows = session.query(cls.dag_id).filter(cls.fileloc_hash == 
file_path_hash).all()

Review Comment:
   ```suggestion
           rows = session.query(cls.dag_id).filter(cls.fileloc_hash == 
file_path_hash, cls.fileloc == dag_file_path).all()
   ```
   
   This should be all it takes -- use the DB index to restrict the rows, and 
then a non-indexed search to only get the actual rows we want.



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