vincbeck commented on code in PR #44456:
URL: https://github.com/apache/airflow/pull/44456#discussion_r1876200836


##########
airflow/dag_processing/collection.py:
##########
@@ -435,14 +456,20 @@ def add_asset_trigger_references(
         refs_to_add: dict[tuple[str, str], set[str]] = {}
         refs_to_remove: dict[tuple[str, str], set[str]] = {}
         triggers: dict[str, BaseTrigger] = {}
+
+        # Optimization: if no asset collected, skip fetching active assets
+        active_assets = _find_active_assets(self.assets.keys(), 
session=session) if self.assets else {}
+
         for name_uri, asset in self.assets.items():
-            asset_model = assets[name_uri]
+            # If the asset belong to a DAG not active or paused, consider 
there is no watcher associated to it
+            asset_watchers = asset.watchers if name_uri in active_assets else 
[]
             trigger_repr_to_trigger_dict: dict[str, BaseTrigger] = {
-                repr(trigger): trigger for trigger in asset.watchers
+                repr(trigger): trigger for trigger in asset_watchers

Review Comment:
   This is not a model, this is the interface/base class of all triggers. Each 
trigger is uniquely identified with 2 piece of informations: the class path of 
the trigger, and the kwargs used to instantiate it. We can safely say that if 
the two are the same, there is no need to create a second one because they are 
the same.
   
   I used `repr` for simplicity because the implementation of `__repr__` in 
`BaseTrigger` is exactly what I need:
   
   ```
   @staticmethod
       def repr(classpath: str, kwargs: dict[str, Any]):
           kwargs_str = ", ".join(f"{k}={v}" for k, v in kwargs.items())
           return f"<{classpath} {kwargs_str}>"
   
       def __repr__(self) -> str:
           classpath, kwargs = self.serialize()
           return self.repr(classpath, kwargs)
   ```
   
   However, you are making a good point saying that someone can modify this 
implementation without knowing the consequences. I can duplicate this 
implementation and put it somewhere, to be on the safe side



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