diff --git a/src/agents/orchestrator.py b/src/agents/orchestrator.py index 5f45369..04a4eed 100644 --- a/src/agents/orchestrator.py +++ b/src/agents/orchestrator.py @@ -1174,7 +1174,7 @@ class AgentOrchestrator: sources_json = json.dumps(sources, ensure_ascii=False) if sources else previous_sources_json await db.execute( - "UPDATE incidents SET summary = ?, sources_json = ?, updated_at = ? WHERE id = ?", + "UPDATE incidents SET summary = ?, sources_json = ?, executive_summary = NULL, updated_at = ? WHERE id = ?", (new_summary, sources_json, now, incident_id), ) @@ -1470,6 +1470,33 @@ class AgentOrchestrator: logger.info(f"Refresh für Lage {incident_id} abgeschlossen: {new_count} neue Artikel") + # Executive Summary im Hintergrund vorab generieren (fuer schnelleren Export) + if new_count > 0: + async def _pregenerate_exec_summary(): + try: + from report_generator import generate_executive_summary + from database import get_db + _db = await get_db() + try: + cursor = await _db.execute( + "SELECT summary, executive_summary FROM incidents WHERE id = ?", + (incident_id,), + ) + _row = await cursor.fetchone() + if _row and _row["summary"] and not _row["executive_summary"]: + es = await generate_executive_summary(_row["summary"]) + await _db.execute( + "UPDATE incidents SET executive_summary = ? WHERE id = ?", + (es, incident_id), + ) + await _db.commit() + logger.info(f"Executive Summary fuer Lage {incident_id} vorberechnet") + finally: + await _db.close() + except Exception as e: + logger.warning(f"Executive Summary Vorberechnung fehlgeschlagen: {e}") + asyncio.create_task(_pregenerate_exec_summary()) + finally: await db.close()