- Add ActionBar component with expandable toolbar for mobile - Add @mention functionality with autocomplete dropdown - Add browser notification system (push, sound, vibration) - Add NotificationSettings modal for user preferences - Add mention badges on room list cards - Add ReportPreview with Markdown rendering and copy/download - Add message copy functionality with hover actions - Add backend mentions field to messages with Alembic migration - Add lots field to rooms, remove templates - Optimize WebSocket database session handling - Various UX polish (animations, accessibility) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2.0 KiB
2.0 KiB
Tasks: Optimize WebSocket Database Sessions
Phase 1: Database Configuration
- T-1.1: 在
app/core/config.py新增連線池環境變數DB_POOL_SIZE(預設: 20)DB_MAX_OVERFLOW(預設: 30)DB_POOL_TIMEOUT(預設: 10)DB_POOL_RECYCLE(預設: 1800)
- T-1.2: 更新
app/core/database.py使用新的環境變數配置 - T-1.3: 更新
.env.example加入新配置說明 - T-1.4: 同步更新
.env加入新的環境變數(使用生產環境建議值)
Phase 2: Context Manager for Short Sessions
- T-2.1: 在
app/core/database.py新增get_db_context()context manager - T-2.2: 新增 async 版本
get_async_db_context()(可選,若未來需要)
Phase 3: WebSocket Router Refactoring
- T-3.1: 修改
app/modules/realtime/router.py移除長期 Session 持有 - T-3.2: 每個訊息處理改用
with get_db_context() as db:模式 - T-3.3: 確保連線認證和房間成員檢查也使用短期 Session
Phase 4: Sequence Number Race Condition Fix
- T-4.1: 修改
MessageService.create_message()使用SELECT ... FOR UPDATE T-4.2: 或改用資料庫 AUTO_INCREMENT + 觸發器方案(不需要,已採用 FOR UPDATE)- T-4.3: 測試並發訊息場景確認無重複 sequence
- 測試腳本:
tests/test_concurrent_messages.py - 測試結果: 100 條訊息從 20 個用戶並發發送,全部成功無重複
- 測試腳本:
Phase 5: Testing & Documentation
- T-5.1: 壓力測試 50+ 並發連線
- 測試: 100 threads × 10 queries = 1000 次連線
- 結果: 100% 成功,263.7 QPS
- T-5.2: 驗證連線池不會耗盡
- Pool size: 20, 0 overflow during test
- T-5.3: 驗證 sequence_number 無重複
- 100 條並發訊息,100 個唯一 sequence numbers
- T-5.4: 更新部署文件
- 更新
.env.example加入連線池配置說明
- 更新
Dependencies
- T-1.* 必須先完成
- T-2.* 在 T-1.* 之後
- T-3.* 依賴 T-2.*
- T-4.* 可與 T-3.* 並行
- T-5.* 在所有實作完成後