Stop over-recursion in post contexts

pull/529/head^2
Andrew Godwin 2023-03-02 10:28:27 -07:00
rodzic 6411a375ba
commit 552a150e57
1 zmienionych plików z 5 dodań i 2 usunięć

Wyświetl plik

@ -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:
descendants.append(child)
queue.append(child)
if child.pk not in seen:
descendants.append(child)
queue.append(child)
seen.add(child.pk)
return ancestors, descendants
def delete(self):