mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-25 08:41:00 +00:00
Stop over-recursion in post contexts
This commit is contained in:
parent
6411a375ba
commit
552a150e57
1 changed files with 5 additions and 2 deletions
|
@ -105,6 +105,7 @@ class PostService:
|
|||
# Retrieve descendants via breadth-first-search
|
||||
descendants: list[Post] = []
|
||||
queue = [self.post]
|
||||
seen: set[str] = set()
|
||||
while queue and len(descendants) < num_descendants:
|
||||
node = queue.pop()
|
||||
child_queryset = (
|
||||
|
@ -119,8 +120,10 @@ class PostService:
|
|||
else:
|
||||
child_queryset = child_queryset.unlisted(include_replies=True)
|
||||
for child in child_queryset:
|
||||
if child.pk not in seen:
|
||||
descendants.append(child)
|
||||
queue.append(child)
|
||||
seen.add(child.pk)
|
||||
return ancestors, descendants
|
||||
|
||||
def delete(self):
|
||||
|
|
Loading…
Reference in a new issue