feat(sse): sync temps réel multi-appareils via Server-Sent Events v0.5.8

- Broadcaster asyncio.Queue avec keepalive 25s (prévient timeout proxy)
- Endpoint GET /api/events/stream (StreamingResponse text/event-stream)
- Broadcast notes_changed / todos_changed / shopping_changed sur toutes mutations
- Hook useServerEvents: EventSource avec reconnexion automatique (3s)
- Pages Notes, Todos, Shopping abonnées aux événements SSE
- nginx: location SSE dédiée (proxy_buffering off, timeout 24h)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-25 20:12:02 +02:00
parent 2129da4f55
commit ec87bc091d
12 changed files with 123 additions and 2 deletions
+6
View File
@@ -5,6 +5,7 @@ from sqlalchemy import select, text, and_
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload
from app.core.broadcaster import broadcaster
from app.core.database import get_session
from app.core.redis import enqueue
from app.models.notes import NoteItem, NoteAttachment
@@ -74,6 +75,7 @@ async def create_note(payload: NoteCreate, session: AsyncSession = Depends(get_s
await session.commit()
await session.refresh(note, ["attachments"])
await enqueue("export_note_markdown", str(note.id))
broadcaster.broadcast("notes_changed")
return note
@@ -97,6 +99,7 @@ async def update_note(
await session.commit()
await session.refresh(note, ["attachments"])
await enqueue("export_note_markdown", str(note.id))
broadcaster.broadcast("notes_changed")
return note
@@ -108,6 +111,7 @@ async def delete_note(note_id: uuid.UUID, session: AsyncSession = Depends(get_se
await session.delete(note)
await session.commit()
await enqueue("remove_note_markdown", str(note_id))
broadcaster.broadcast("notes_changed")
return Response(status_code=204)
@@ -151,6 +155,7 @@ async def add_attachment(
await session.commit()
await session.refresh(note, ["attachments"])
await enqueue("export_note_markdown", str(note_id))
broadcaster.broadcast("notes_changed")
return note
@@ -177,4 +182,5 @@ async def delete_attachment(
await session.delete(att)
await session.commit()
await enqueue("export_note_markdown", str(note_id))
broadcaster.broadcast("notes_changed")
return Response(status_code=204)