rjgoyln commented on code in PR #70620:
URL: https://github.com/apache/airflow/pull/70620#discussion_r3674057661
##########
airflow-core/src/airflow/serialization/definitions/xcom_arg.py:
##########
@@ -145,14 +154,102 @@ def iter_references(self) -> Iterator[tuple[Operator,
str]]:
yield from arg.iter_references()
+def _match_referenced_tasks(model: Any, keys: Iterable[tuple[str, str]]) ->
tuple[Any, Any]:
+ """
+ Build filters selecting rows of ``model`` for any of the given ``(dag_id,
task_id)``.
+
+ Matching the two columns independently rather than as a row value keeps
the query
+ portable. That is wider than the key set only if the keys span several
Dags, which
+ the callers never do, and callers read results back by exact key
regardless.
+ """
+ dag_ids, task_ids = zip(*keys)
+ return model.dag_id.in_(set(dag_ids)), model.task_id.in_(set(task_ids))
+
+
+def prefetch_map_lengths(
+ xcom_args: Iterable[SchedulerXComArg], run_id: str, *, session: Session
+) -> dict[tuple[str, str], int]:
+ """
+ Resolve the map length of every task referenced by ``xcom_args`` in bulk.
+
+ Passing the result to :func:`get_task_map_length` as ``lengths`` keeps the
number of
+ queries constant no matter how many arguments -- and how many tasks nested
inside
+ ``zip()``/``concat()`` arguments -- have to be resolved.
+
+ Tasks whose length is not known yet are absent from the result, mirroring
the
+ ``None`` that :func:`get_task_map_length` returns for them.
+ """
+ from airflow.models.taskinstance import TaskInstance
+ from airflow.models.taskmap import TaskMap
+ from airflow.models.xcom import XComModel
+ from airflow.serialization.definitions.mappedoperator import is_mapped
Review Comment:
No — I checked and there is no cycle. I moved all four to the top, and
dropped the same now-redundant local
imports from `get_task_map_length` also.
--
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]