Files
DashBoard/openspec/changes/archive/2026-02-09-harden-mid-section-defect/tasks.md
egg af59031f95 feat(mid-section-defect): harden with distributed lock, rate limit, filter separation, abort, SQL classification and tests
Address 6 code review findings (P0-P3): add Redis distributed lock to prevent
duplicate Oracle pipeline on cold cache, apply rate limiting to 3 high-cost
routes, separate UI filter state from committed query state, add AbortController
for request cancellation, push workcenter group classification into Oracle SQL
CASE WHEN, and add 18 route+service tests. Also add workcenter group selection
to job-query equipment selector and rename button to "查詢".

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 09:32:14 +08:00

2.2 KiB
Raw Blame History

1. P0 — 分散式鎖防止重複管線執行

  • 1.1 在 mid_section_defect_service.pyquery_analysis() cache miss 後加入 try_acquire_lock / release_lock 包裹計算區段
  • 1.2 實作 lock-or-wait 邏輯:未取得鎖時輪詢 cache_get() 每 0.5s,最多 90s超時 fail-open
  • 1.3 在 finally 區塊確保鎖釋放,取得鎖後再做 double-check cache

2. P1a — 高成本路由限速

  • 2.1 在 mid_section_defect_routes.py import configured_rate_limit 並建立 3 個限速器analysis 6/60s、detail 15/60s、export 3/60s
  • 2.2 將限速 decorator 套用到 /analysis/analysis/detail/export 三個路由

3. P1b + P2a — 前端篩選分離與請求取消

  • 3.1 在 App.vue 新增 committedFilters refhandleQuery() 時從 filters 快照
  • 3.2 修改 buildFilterParams()exportCsv() 讀取 committedFilters 而非 filters
  • 3.3 initPage() 設定預設日期後同步快照到 committedFilters
  • 3.4 從 useAutoRefresh 解構 createAbortSignal,在 loadAnalysis() 加入 'msd-analysis' signal
  • 3.5 loadDetail() 接受外部 signal 參數,獨立翻頁時使用 'msd-detail' key
  • 3.6 loadAnalysis()loadDetail() catch 區塊靜默處理 AbortError

4. P2b — 上游歷史 SQL 端分類

  • 4.1 修改 upstream_history.sql CTE 加入 CASE WHENWORKCENTERNAME 分類為 WORKCENTER_GROUP12 組 + NULL fallback
  • 4.2 確保 CASE 順序正確(元件切割/PKG_SAW切割 之前)
  • 4.3 修改 _fetch_upstream_history() 讀取 SQL 回傳的 WORKCENTER_GROUP 欄位,移除 get_workcenter_group() 逐行呼叫與 order 4-11 過濾

5. P3 — 測試覆蓋

  • 5.1 建立 tests/test_mid_section_defect_routes.pysuccess、400 參數驗證、500 service 失敗、429 rate limit共 9 個測試)
  • 5.2 建立 tests/test_mid_section_defect_service.py日期驗證、分頁邏輯、loss reasons 快取(共 9 個測試)

6. 驗證

  • 6.1 npm run build 前端建置通過
  • 6.2 pytest tests/test_mid_section_defect_routes.py tests/test_mid_section_defect_service.py -v 全部通過