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>
2.2 KiB
2.2 KiB
1. P0 — 分散式鎖防止重複管線執行
- 1.1 在
mid_section_defect_service.py的query_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.pyimportconfigured_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新增committedFiltersref,handleQuery()時從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.sqlCTE 加入CASE WHEN將WORKCENTERNAME分類為WORKCENTER_GROUP(12 組 + 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.py:success、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全部通過