feat: implement kanban real-time sync and fix workload cache

## Kanban Real-time Sync (NEW-002)
- Backend:
  - WebSocket endpoint: /ws/projects/{project_id}
  - Project room management in ConnectionManager
  - Redis Pub/Sub: project:{project_id}:tasks channel
  - Task CRUD event publishing (5 event types)
  - Redis connection retry with exponential backoff
  - Race condition fix in broadcast_to_project

- Frontend:
  - ProjectSyncContext for WebSocket management
  - Reconnection with exponential backoff (max 5 attempts)
  - Multi-tab event deduplication via event_id
  - Live/Offline connection indicator
  - Optimistic updates with rollback

- Spec:
  - collaboration spec: +1 requirement (Project Real-time Sync)
  - 7 new scenarios for real-time sync

## Workload Cache Fix (NEW-001)
- Added cache invalidation to all task endpoints:
  - create_task, update_task, update_task_status
  - delete_task, restore_task, assign_task
- Extended to clear heatmap cache as well

## OpenSpec Archive
- 2026-01-05-add-kanban-realtime-sync

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
beabigegg
2026-01-05 20:28:42 +08:00
parent 9b220523ff
commit 69b81d9241
13 changed files with 1470 additions and 31 deletions

View File

@@ -498,24 +498,24 @@
## 未實作功能 (Missing Features)
| ID | 模組 | 功能 | 後端 | 前端 | 優先級 |
|----|------|------|:----:|:----:|--------|
| FEAT-001 | Task Management | 自定義欄位 (Custom Fields) | 缺 | 缺 | 高 |
| FEAT-002 | Task Management | 看板視角 (Kanban View) | 有 | | 高 |
| FEAT-003 | Task Management | 甘特圖視角 (Gantt View) | 有 | 缺 | 中 |
| FEAT-004 | Task Management | 行事曆視角 (Calendar View) | 有 | 缺 | 中 |
| FEAT-005 | Task Management | 子任務建立 UI | 有 | 缺 | 中 |
| FEAT-006 | Task Management | 拖拉變更狀態 | 有 | | 中 |
| FEAT-007 | Resource Management | 負載熱圖 UI | 有 | | 高 |
| FEAT-008 | Resource Management | 專案健康看板 | | | 中 |
| FEAT-009 | Resource Management | 容量更新 API | | | 低 |
| FEAT-010 | Document Management | AES-256 加密存儲 | 缺 | N/A | 高 |
| FEAT-011 | Document Management | 動態浮水印 | | N/A | 中 |
| FEAT-012 | Document Management | 版本還原 UI | 有 | 缺 | 低 |
| FEAT-013 | Automation | 排程觸發器執行 | 部分 | | 中 |
| FEAT-014 | Automation | 更新欄位動作 | 缺 | 缺 | 低 |
| FEAT-015 | Automation | 自動指派動作 | 缺 | 缺 | 低 |
| FEAT-016 | Audit Trail | 稽核完整性驗證 UI | 有 | 缺 | 低 |
| ID | 模組 | 功能 | 後端 | 前端 | 優先級 | 狀態 |
|----|------|------|:----:|:----:|--------|------|
| FEAT-001 | Task Management | 自定義欄位 (Custom Fields) | 缺 | 缺 | 高 | 待開發 |
| FEAT-002 | Task Management | 看板視角 (Kanban View) | 有 | | 高 | ✅ 已完成 (KanbanBoard.tsx) |
| FEAT-003 | Task Management | 甘特圖視角 (Gantt View) | 有 | 缺 | 中 | 待開發 |
| FEAT-004 | Task Management | 行事曆視角 (Calendar View) | 有 | 缺 | 中 | 待開發 |
| FEAT-005 | Task Management | 子任務建立 UI | 有 | 缺 | 中 | 待開發 |
| FEAT-006 | Task Management | 拖拉變更狀態 | 有 | | 中 | ✅ 已完成 (KanbanBoard drag-drop) |
| FEAT-007 | Resource Management | 負載熱圖 UI | 有 | | 高 | ✅ 已完成 (WorkloadPage.tsx) |
| FEAT-008 | Resource Management | 專案健康看板 | | | 中 | ✅ 已完成 (ProjectHealthPage.tsx) |
| FEAT-009 | Resource Management | 容量更新 API | | N/A | 低 | ✅ 已完成 (PUT /api/users/{id}/capacity) |
| FEAT-010 | Document Management | AES-256 加密存儲 | 缺 | N/A | 高 | 待開發 |
| FEAT-011 | Document Management | 動態浮水印 | | N/A | 中 | ✅ 已完成 (watermark_service.py) |
| FEAT-012 | Document Management | 版本還原 UI | 有 | 缺 | 低 | 待開發 |
| FEAT-013 | Automation | 排程觸發器執行 | | N/A | 中 | ✅ 已完成 (trigger_scheduler.py) |
| FEAT-014 | Automation | 更新欄位動作 | 缺 | 缺 | 低 | 待開發 |
| FEAT-015 | Automation | 自動指派動作 | 缺 | 缺 | 低 | 待開發 |
| FEAT-016 | Audit Trail | 稽核完整性驗證 UI | 有 | 缺 | 低 | 待開發 |
---
@@ -677,6 +677,16 @@
| 日期 | 變更名稱 | 影響的 Spec |
|------|----------|-------------|
| 2025-12-28 | add-user-auth | user-auth |
| 2025-12-28 | add-task-management | task-management |
| 2025-12-28 | add-resource-workload | resource-management |
| 2025-12-29 | add-collaboration | collaboration |
| 2025-12-29 | add-audit-trail | audit-trail |
| 2025-12-29 | add-automation | automation |
| 2025-12-29 | add-document-management | document-management |
| 2025-12-29 | fix-audit-trail | audit-trail |
| 2025-12-30 | fix-realtime-notifications | collaboration |
| 2025-12-30 | fix-weekly-report | automation |
| 2026-01-04 | add-rate-limiting | user-auth |
| 2026-01-04 | enhance-frontend-ux | task-management |
| 2026-01-04 | add-resource-management-ui | resource-management |
@@ -687,5 +697,36 @@
---
## 新發現問題 (New Issues)
### NEW-001: 負載快取失效未在任務變更時觸發
- **類型**: Bug
- **模組**: Backend - Resource Management
- **檔案**: `backend/app/api/tasks/router.py`
- **問題描述**: `workload_cache.py` 定義了 `invalidate_user_workload_cache()` 函數,但任務指派、時間估算、狀態變更時未調用,導致負載熱圖顯示過期數據。
- **影響**: 使用者變更任務後,負載熱圖不會即時反映最新分配
- **建議修復**: 在 `tasks/router.py` 的 `update_task`、`update_task_status`、`assign_task` 等 endpoints 調用 `invalidate_user_workload_cache()`
- **狀態**: [x] 已修復 (2026-01-04)
- **修復內容**:
- 在 `create_task`、`update_task`、`update_task_status`、`delete_task`、`restore_task`、`assign_task` 端點加入 `invalidate_user_workload_cache()` 呼叫
- 同時清除 `workload:heatmap:*` 快取確保熱圖即時更新
---
### NEW-002: 看板缺少即時同步功能
- **類型**: 功能缺失
- **模組**: Frontend + Backend - Task Management
- **檔案**:
- `backend/app/api/websocket/router.py`
- `frontend/src/components/KanbanBoard.tsx`
- **問題描述**: WebSocket 目前僅用於通知推送,看板視角沒有即時同步功能。當其他用戶拖拉任務變更狀態時,當前用戶的看板不會即時更新。
- **影響**: 多人協作時可能產生狀態衝突
- **建議修復**: 擴展 WebSocket 支援任務變更事件廣播,前端訂閱並即時更新看板
- **狀態**: [ ] 待開發
---
*此文件由 Claude Code 自動生成於 2026-01-04*
*更新於 2026-01-04*