Files
egg 599802b818 feat: Add Chat UX improvements with notifications and @mention support
- 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>
2025-12-08 08:20:37 +08:00

52 lines
2.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Tasks: Optimize WebSocket Database Sessions
## Phase 1: Database Configuration
- [x] **T-1.1**: 在 `app/core/config.py` 新增連線池環境變數
- `DB_POOL_SIZE` (預設: 20)
- `DB_MAX_OVERFLOW` (預設: 30)
- `DB_POOL_TIMEOUT` (預設: 10)
- `DB_POOL_RECYCLE` (預設: 1800)
- [x] **T-1.2**: 更新 `app/core/database.py` 使用新的環境變數配置
- [x] **T-1.3**: 更新 `.env.example` 加入新配置說明
- [x] **T-1.4**: 同步更新 `.env` 加入新的環境變數(使用生產環境建議值)
## Phase 2: Context Manager for Short Sessions
- [x] **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
- [x] **T-3.1**: 修改 `app/modules/realtime/router.py` 移除長期 Session 持有
- [x] **T-3.2**: 每個訊息處理改用 `with get_db_context() as db:` 模式
- [x] **T-3.3**: 確保連線認證和房間成員檢查也使用短期 Session
## Phase 4: Sequence Number Race Condition Fix
- [x] **T-4.1**: 修改 `MessageService.create_message()` 使用 `SELECT ... FOR UPDATE`
- [ ] ~~**T-4.2**: 或改用資料庫 AUTO_INCREMENT + 觸發器方案~~ (不需要,已採用 FOR UPDATE)
- [x] **T-4.3**: 測試並發訊息場景確認無重複 sequence
- 測試腳本: `tests/test_concurrent_messages.py`
- 測試結果: 100 條訊息從 20 個用戶並發發送,全部成功無重複
## Phase 5: Testing & Documentation
- [x] **T-5.1**: 壓力測試 50+ 並發連線
- 測試: 100 threads × 10 queries = 1000 次連線
- 結果: 100% 成功263.7 QPS
- [x] **T-5.2**: 驗證連線池不會耗盡
- Pool size: 20, 0 overflow during test
- [x] **T-5.3**: 驗證 sequence_number 無重複
- 100 條並發訊息100 個唯一 sequence numbers
- [x] **T-5.4**: 更新部署文件
- 更新 `.env.example` 加入連線池配置說明
## Dependencies
- T-1.* 必須先完成
- T-2.* 在 T-1.* 之後
- T-3.* 依賴 T-2.*
- T-4.* 可與 T-3.* 並行
- T-5.* 在所有實作完成後