ProdLaunch
This commit is contained in:
@@ -923,9 +923,13 @@ async def get_thread(
|
||||
|
||||
# Carica ricorsivamente tutti i messaggi del thread dalla radice
|
||||
# Limita a posta_certificata (esclude accettazioni, consegne, ecc.)
|
||||
# Depth limit per evitare stack overflow su thread eccezionalmente profondi
|
||||
_THREAD_MAX_DEPTH = 100
|
||||
thread_messages: list[Message] = []
|
||||
|
||||
async def _collect(msg_id: uuid.UUID) -> None:
|
||||
async def _collect(msg_id: uuid.UUID, depth: int = 0) -> None:
|
||||
if depth >= _THREAD_MAX_DEPTH:
|
||||
return
|
||||
result = await db.execute(
|
||||
select(Message)
|
||||
.where(
|
||||
@@ -951,7 +955,7 @@ async def get_thread(
|
||||
)
|
||||
children = list(children_result.scalars().all())
|
||||
for child in children:
|
||||
await _collect(child.id)
|
||||
await _collect(child.id, depth + 1)
|
||||
|
||||
await _collect(root_id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user