Skip to content

Commit 0acc9b7

Browse files
authored
Optimize tree method to reduce time complexity (#400)
1 parent fea6dd3 commit 0acc9b7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

quixstreams/core/stream/stream.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,19 @@ def tree(self) -> List[Self]:
234234
"""
235235
Return a list of all parent Streams including the node itself.
236236
237-
The tree is ordered from child to parent (current node comes first).
237+
The tree is ordered from parent to child (current node comes last).
238238
:return: a list of `Stream` objects
239239
"""
240+
240241
tree_ = [self]
241242
node = self
242243
while node.parent:
243-
tree_.insert(0, node.parent)
244+
tree_.append(node.parent)
244245
node = node.parent
246+
247+
# Reverse to get expected ordering.
248+
tree_.reverse()
249+
245250
return tree_
246251

247252
def compose_returning(self) -> ReturningExecutor:

0 commit comments

Comments
 (0)