uranusjr commented on code in PR #22849:
URL: https://github.com/apache/airflow/pull/22849#discussion_r846623285
##########
airflow/models/taskinstance.py:
##########
@@ -323,16 +323,19 @@ class _LazyXComAccess(collections.abc.Sequence):
"""Wrapper to lazily pull XCom with a sequence-like interface.
Note that since the session bound to the parent query may have died when we
- actually access the sequence's content, we must create a new fresh session
+ actually access the sequence's content, we must a new fresh session
for every function call with ``with_session()``.
"""
def __init__(self, query: Query):
self._q = query
+ self._len = None
def __len__(self):
- with self._get_bound_query() as query:
- return query.count()
+ if self._len is None:
+ with self._get_bound_query() as query:
+ self._len = query.count()
+ return self._len
Review Comment:
Or we could `@cache` this?
--
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]