Commit Graph

91 Commits

Author SHA1 Message Date
egg
cd54d7cdcb docs: update README for Hold/cascade/security features and sync deploy script entries
Update README v5.5 with Hold Overview/History pages, cascade filters,
table query whitelist, WIP filter preservation, and review hardening
changelog. Sync start_server.sh required frontend entries to cover all
13 Vite-built pages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 10:57:13 +08:00
egg
f90a8a57b4 fix(security): add table_name whitelist to prevent SQL injection in table query APIs
The /api/query_table and /api/get_table_columns endpoints accepted arbitrary
table_name values that were interpolated directly into SQL f-strings. Since
api_public is true, any unauthenticated user could exploit this. Now validates
table_name and time_field against TABLES_CONFIG before reaching the database.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 10:44:56 +08:00
egg
dfaf0bc611 fix(review): harden security, stability, and efficiency across 7 dashboard pages
Security: sanitize innerHTML with escapeHtml in job-query, add rate limiting
to job-query and job-export endpoints, upgrade login rate limiter to Redis
cross-worker with in-memory fallback, cap resource_ids array at 50, limit
CSV export date range to 365 days.

Stability: wrap initPage calls in onMounted for wip-overview, resource-status,
and resource-history; unload inactive iframes in portal to free memory; add
±15% jitter to auto-refresh timers in useAutoRefresh and useQcGateData; batch
expanded job history loads with concurrency limit of 5.

Config: reorganize sidebar drawers, move query-tool to dev status.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 10:29:49 +08:00
egg
7b3f4b2cc1 feat(resource): add cascade machine/family filters to status and history pages
Add interdependent filter controls where upstream filters (workcenter group,
boolean flags) dynamically narrow downstream options (family, machine).
MultiSelect component moved to resource-shared with searchable support.
Backend endpoints accept families and resource_ids params, leveraging
existing Redis-cached resource metadata for client-side cascade filtering.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 09:44:04 +08:00
egg
e2ce75b004 fix(hold): dedup equipment cache, fix portal iframe, improve Hold dashboards
- Equipment cache: add freshness gate so only 1 Oracle query per 5-min cycle
  across 4 gunicorn workers; sync worker waits before first refresh
- Portal: add frame-busting to prevent recursive iframe nesting
- Hold Overview: remove redundant TreeMap, add Product & Future Hold Comment
  columns to LotTable
- Hold History: switch list.sql JOIN from DW_MES_LOT_V (WIP snapshot) to
  DW_MES_CONTAINER (historical master) for reliable Product data; add
  Future Hold Comment column; fix comment truncation with hover tooltip
- Page status: reorganize drawer groupings

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 09:01:02 +08:00
egg
be22571421 feat(wip): preserve filters between Overview and Detail with thundering-herd fix
URL is now single source of truth for filter state (workorder, lotid,
package, type, status) across WIP Overview and Detail pages. Drill-down
carries all filters + status; back button dynamically reflects Detail
changes. Backend Detail API now supports pj_type filter parameter.

Harden concurrency: add pagehide abort for MPA navigation, double-check
locking on Redis JSON parse and snapshot build to prevent thread pool
saturation during rapid page switching. Fix watchdog setsid and PID
discovery. Fix test_realtime_equipment_cache RUNCARDLOTID field mismatch.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 07:22:48 +08:00
egg
3a15b0abaf fix(hold-overview): remove WIP Overview back link from independent report
Hold 即時概況 is an independent report, not a drill-down from WIP Overview.
The back link caused iframe navigation to WIP Overview while the sidebar
still highlighted Hold 即時概況.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 18:33:46 +08:00
egg
d033ffeb26 fix(resource-status): sort machine names, fix LOT click, support multi-select matrix filter
- Sort level-2 resource nodes alphabetically in status matrix hierarchy
- Fix LOT_COUNT using raw row count when no valid RUNCARDLOTID exists,
  causing LOT badge to render but click to silently fail
- Change matrix cell filter from single-select to multi-select (OR logic)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 18:25:20 +08:00
egg
9a4e08810b feat(hold-history): add Hold 歷史績效 Dashboard with trend, pareto, duration, and detail views
New independent report page based on DWH.DW_MES_HOLDRELEASEHISTORY providing
historical hold/release performance analysis. Includes daily trend with Redis
caching, reason Pareto with click-to-filter, duration distribution with
click-to-filter, multi-select record type filter (new/on_hold/released),
workcenter-group mapping via memory cache, and server-side paginated detail
table. All 32 backend tests passing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 18:03:08 +08:00
egg
8225863a85 feat(hold-overview): add Hold Lot Overview page with TreeMap, Matrix, and cascade filtering
Provide managers with a dedicated page to analyze hold lots across all stations.
Extends existing service functions (get_hold_detail_summary, get_hold_detail_lots,
get_wip_matrix) with optional parameters for backward compatibility, adds one new
function (get_hold_overview_treemap), and registers the page in the portal navigation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 13:02:24 +08:00
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
egg
8b1b8da59b feat(mid-section-defect): add TMTT reverse traceability analysis with paginated detail API
New page for tracing TMTT test station defects back to upstream machines,
stations, and workflows. Three-stage data pipeline (TMTT detection →
SPLITFROMID BFS + COMBINEDASSYLOTS merge expansion → upstream history),
6 KPI cards, 6 Pareto charts, daily trend, paginated LOT detail table.

Summary/detail API separation reduces response from 72 MB to ~16 KB summary
+ ~110 KB/page detail. Loss reasons cached in Redis with 24h TTL (205 types).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 08:24:04 +08:00
egg
720e190bc6 feat(resource): migrate resource-status and resource-history from Jinja2 to Vue 3 + Vite
Rewrite both resource pages (1,697 lines vanilla JS + 3,200 lines Jinja2 templates)
as Vue 3 SFC components. Extract resource-shared/ module with shared CSS, E10 status
constants, and HierarchyTable tree component. History page charts use vue-echarts,
Status page reuses useAutoRefresh composable with 5-minute interval.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 18:19:32 +08:00
egg
a2653b8139 feat(wip): migrate WIP trio pages from Jinja2 to Vue 3 + Vite
Migrate /wip-overview, /wip-detail, and /hold-detail (1,941 lines vanilla JS)
to Vue 3 SFC architecture. Extract shared CSS/constants/components to
wip-shared/. Switch Pareto charts to vue-echarts with autoresize. Replace
Jinja2 template injection with frontend URL params + constant classification
for Hold Detail. Add 10-min auto-refresh + AbortController to Hold Detail.
Remove three Jinja2 templates, update Flask routes to send_from_directory.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 16:39:20 +08:00
egg
dcbf6dcf1f feat(tables): migrate /tables page from Jinja2 to Vue 3 + Vite
Rewrite 237-line vanilla JS + Jinja2 template into Vue 3 SFC components
(App.vue, TableCatalog.vue, DataViewer.vue, useTableData composable).
Establishes apiPost POST request pattern for pure Vite pages. Removes
templates/index.html, updates Vite entry to HTML, and Flask route to
send_from_directory. Includes sql_fragments WHERE_CLAUSE escaping fix,
updated integration tests, and OpenSpec artifact archive.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 14:52:14 +08:00
egg
44b89599a4 fix(resource-cache): resolve DataFrame TTL eviction causing empty resource status
_records_from_index() returned [] when process-level DataFrame cache (30s TTL)
expired but derived index remained ready=true. Now reloads from Redis via
_get_cached_data() instead of returning empty.

Also rename /resource page from "機台狀態" to "設備即時概況" in page_status.json.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 14:42:29 +08:00
egg
3c77d4d028 docs: update README with QC-GATE report, dynamic drawer nav, and Vue 3 architecture
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 13:09:28 +08:00
egg
bf7285fb51 feat(qc-gate): add QC-GATE real-time LOT status report as first pure Vue 3 + Vite page
Introduce QC-GATE station monitoring with stacked bar chart and filterable LOT table,
using Vue 3 SFC + ECharts via npm. Establishes the pure Vite page architecture pattern
(no Jinja2) for future page migration. Also removes stale design files and README.mdj.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 13:06:59 +08:00
egg
9b1d2edc52 feat(portal): implement dynamic drawer/page navigation management
Replace hardcoded sidebar drawer configuration with admin-manageable
dynamic system. Extend page_status.json with drawer definitions and
page assignments, add drawer CRUD API endpoints, render portal sidebar
via Jinja2 loops, and extend /admin/pages UI with drawer management.
Fix multi-worker cache invalidation via mtime-based staleness detection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 11:34:04 +08:00
egg
706c8ba52c feat(portal): refactor navigation from drawer to sidebar layout
Replace collapsible <details> drawers with a persistent left sidebar for
報表類, 查詢類, and 開發工具 categories. Unify dev tools handling via
data-tool-src attribute instead of onclick openTool(). Also release
tmtt-defect page status from dev to released.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 10:16:14 +08:00
egg
e88427f4b4 chore: adopt legacy dashboard master history for non-force cutover 2026-02-09 09:25:51 +08:00
egg
1e6d6dbd31 feat: complete dashboard-vite parity and fix portal health/csp regressions 2026-02-09 09:22:23 +08:00
beabigegg
21ec1ea541 fix(security): 重構 table query 至標準架構,修復 SQL injection 與 regex 安全問題
- 重構 get_table_data/get_table_columns 使用 TABLES_CONFIG 白名單 + QueryBuilder + read_sql_df
- 移除 get_db_connection() 直連,改用連線池 + 熔斷器 + 慢查詢監控
- get_engine() 從 Flask Config 讀取 DB_POOL_SIZE/DB_MAX_OVERFLOW
- query_table limit 上限 10,000 防止記憶體溢出
- wip_service 6 處 str.contains 加 regex=False 防止 ReDoS

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 07:35:07 +08:00
beabigegg
cf194bc3a3 chore: finalize vite migration hardening and watchdog logging 2026-02-08 22:55:38 +08:00
beabigegg
c8e225101e chore: finalize vite migration hardening and archive openspec changes 2026-02-08 20:03:36 +08:00
beabigegg
b56e80381b chore: reinitialize project with vite architecture 2026-02-08 08:30:48 +08:00
beabigegg
32f3e18e9d feat: 新增 TMTT 印字與腳型不良分析頁面,修復批次追蹤工具問題
新增 TMTT 不良分析功能:
- SQL CTE 查詢合併 LOTWIPHISTORY + LOTREJECTHISTORY + CONTAINER
- 服務層:KPI、五維度 Pareto 圖表、每日趨勢、明細表
- API 路由 /api/tmtt-defect/analysis 與 /export
- 前端:單欄圖表佈局、ECharts Pareto + 趨勢圖、明細鑽取篩選
- 單元測試與整合測試 (33 tests)

修復批次追蹤工具:
- 修復 Decimal * float TypeError (Oracle 回傳 decimal.Decimal)
- 改進批次清單查詢:ROW_NUMBER 去重保留最晚下機、帶入產品資訊
- 更新不良統計欄位定義 (TOTAL_DEFECT_QTY)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 20:18:04 +08:00
beabigegg
e5504dea26 feat(query-tool): 改進前後批查詢邏輯與產品資訊顯示
- 前後批查詢改為依 PJ_TYPE 搜尋,移除 SPECNAME 限制
- 時間窗口從 24 小時擴大至 168 小時 (1 週)
- 生產歷程與前後批新增產品資訊欄位 (PJ_TYPE, BOP, Wafer Lot)
- 前後批 Modal 顯示設備名稱而非 ID
- 整合站點篩選器與批次選擇器至統一選擇列

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-06 11:11:58 +08:00
beabigegg
d468adaf3b feat(query-tool): 新增站點群組篩選功能
在批次追蹤工具中加入 WORKCENTER GROUP 篩選功能,讓使用者可以
選擇特定站點群組來過濾生產歷程,減少資料量提升查詢效能。

變更內容:
- 新增 /api/query-tool/workcenter-groups API 端點
- 修改 lot-history API 支援 workcenter_groups 參數
- 前端新增多選下拉選單篩選器 UI
- 後端 SQL 層級過濾,複用 filter_cache 機制
- 新增對應的單元測試和整合測試

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 20:03:25 +08:00
beabigegg
94e5d8c5c3 feat: 新增批次追蹤工具 (Query Tool)
新增完整的批次追蹤和設備時段查詢功能:

批次追蹤功能:
- 支援 LOT ID / 流水號 / GA工單 三種查詢方式
- 生產歷程查詢 (DW_MES_LOTWIPHISTORY)
- 前後批比對 (ROW_NUMBER 窗口函數)
- 關聯資料查詢 (物料/不良/HOLD/JOB)
- TMTT 成品流水號對應查詢

設備時段查詢功能:
- 設備狀態時數統計
- 批次清單查詢
- 物料消耗彙總
- 不良統計
- JOB 紀錄查詢

技術改進:
- 新增 read_sql_df_slow() 支援慢查詢專用連線和超時控制
- 修正時區處理使用 TW_TIMEZONE (GMT+8)
- 新增 15 個 SQL 查詢檔案
- 完整的單元測試和 API 測試

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 19:42:54 +08:00
beabigegg
dd520641d1 refactor: 統一設備維修查詢的欄位名稱
- 前端表格標題「工單 ID」改為「JOBID」避免與 LOT ID 混淆
- CSV 匯出欄位改用原始資料庫欄位名稱,與 SQL 查詢結果一致

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 19:47:20 +08:00
beabigegg
1d798a290c 移除ai助手 2026-02-04 17:58:29 +08:00
beabigegg
4a470fb6a6 docs: 更新專案開發指南與架構文檔
- 將 claude.md 重命名為 CLAUDE.md (符合官方慣例)
- 大幅擴充 architecture_findings.md (311→935 行)
- 新增章節: SQL 集中管理、熔斷器、API 響應格式、認證授權、
  頁面狀態管理、日誌系統、健康檢查、Blueprint 結構、配置管理、
  錯誤處理模式
- 修正 MesApi 位置 (api.js → mes-api.js)
- 移除敏感資訊,改用 placeholder 格式

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 17:57:33 +08:00
beabigegg
097f72f8b9 fix: 修正熔斷器狀態顯示使用 window_size 取代 total_count
前端熔斷器狀態原本顯示「失敗: 0/0」,因為 total_count 是實際記錄
的操作數量。改為使用 window_size 顯示「失敗: 0/10」更直觀。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 17:32:05 +08:00
beabigegg
858427352c security: 完成安全稽核修復與測試配置更新
安全性改進:
- 新增 Session Cookie 安全設定 (SECURE, HTTPONLY, SAMESITE)
- 新增登入端點速率限制防止暴力破解攻擊 (5次/5分鐘)
- 將 dashboard_service 和 resource_service 的 print() 轉換為 logger
- 新增 CORS 環境變數配置範例

文件更新:
- README.md 新增使用者操作指南
- .gitignore 新增 Windows 特殊檔案 nul

測試修復:
- 修正壓力測試預設端口 (5000 → 8080)
- 修正壓力測試使用已發布頁面的標籤名稱
- 修正認證測試正確 mock LOCAL_AUTH_ENABLED

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 17:25:05 +08:00
beabigegg
de0904ffa3 docs: 同步套件清單並補齊缺少的依賴項
- environment.yml: 補齊 redis, hiredis, requests, psutil
- pyproject.toml: 補齊 redis, hiredis, psutil,新增 Python 3.10/3.11 分類
- requirements.txt: 新增版本策略說明與分類註解
- 三個檔案現已完全同步,使用最低版本限制 (>=) 以允許安全性更新

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 16:38:57 +08:00
beabigegg
5299d187bc security: 移除程式碼中硬編碼的敏感資訊
- 移除 database.py、settings.py、auth_service.py 中的硬編碼預設值
- 移除 tools/*.py 中的硬編碼 IP 位址和服務名稱
- 更新 generate_documentation.py 移除硬編碼的帳號密碼
- 更新 MES_Database_Reference.md 和 Oracle_Authorized_Objects.md 移除敏感資訊
- 更新 .env.example 和 README.md 使用 placeholder 值
- 所有敏感設定現在必須透過 .env 檔案配置

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 16:34:32 +08:00
beabigegg
ed60701465 feat: 新增設備維修查詢工具與修復 AJAX 認證重定向問題
設備維修查詢工具:
- 新增 job_query_routes.py 與 job_query_service.py 提供工單查詢 API
- 新增 SQL 查詢檔案 (job_list, job_txn_detail, job_txn_export)
- 新增 job_query.html 前端頁面支援設備選擇、日期範圍查詢與 CSV 匯出
- 整合 portal.html 導航與 page_status.json 頁面註冊
- 新增完整測試 (test_job_query_routes.py, test_job_query_service.py)

AJAX 認證修復:
- 修復 admin 路由對 AJAX 請求返回 302 導致前端卡住的問題
- 新增 _is_ajax_request() 偵測函式於 permissions.py
- 修改 admin_required 裝飾器對 AJAX 請求返回 JSON 401
- 修改 app.py before_request 鉤子支援 AJAX 認證失敗處理
- 更新 performance.html 使用 fetchWithAuth() 處理 401 重定向

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 15:45:03 +08:00
beabigegg
dd0ae3ee54 feat: Excel 批次查詢新增進階條件功能
- 新增欄位類型偵測:自動識別 Excel 與 Oracle 欄位類型並顯示類型標籤
- 新增 LIKE 模糊查詢:支援包含/開頭/結尾三種模式,上限 100 個關鍵字
- 新增日期範圍篩選:支援起始/結束日期,範圍限制 365 天
- 新增大型資料表效能警告:超過 1000 萬筆時提示使用日期範圍縮小查詢
- 新增 /execute-advanced API 端點整合所有進階條件
- 新增 /table-metadata 端點取得欄位類型資訊
- 新增完整測試套件:76 個測試(單元/整合/E2E)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 14:05:19 +08:00
beabigegg
cd7f5a522b fix: 修復 Worker 退出時執行緒卡住導致 timeout 問題
- 增加 graceful_timeout 從 10s 到 30s,給予執行緒足夠清理時間
- worker_exit hook 新增停止背景同步執行緒邏輯
- 調整 SLOW_QUERY_THRESHOLD 預設值為 5.0s (即時視圖查詢通常需 2-5s)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 13:18:28 +08:00
beabigegg
0669a92c39 feat: 效能監控頁面新增日誌分頁與 UI 優化
- 系統日誌改為每頁顯示 50 筆,新增分頁控制項
- 新增 count_logs() 方法支援總數查詢
- query_logs() 支援 offset 參數進行分頁
- API 新增 total 欄位回傳過濾後總數
- 「返回首頁」連結移至 Header 區域
- 新增 2 個分頁功能測試案例

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 08:32:31 +08:00
beabigegg
13acbfc71b feat: 新增效能監控、熔斷器保護與 Worker 重啟控制功能
新增功能:
- 效能監控儀表板 (/admin/performance):系統狀態、查詢延遲、日誌檢視
- 熔斷器 (Circuit Breaker):CLOSED/OPEN/HALF_OPEN 狀態保護資料庫
- 效能指標收集:P50/P95/P99 延遲追蹤、慢查詢統計
- SQLite 日誌儲存:結構化日誌、保留策略、手動清理功能
- Worker Watchdog:透過 systemd 服務支援優雅重啟
- 統一 API 回應格式:success_response/error_response 標準化
- 深度健康檢查端點 (/health/deep)
- 404/500 錯誤頁面模板

Bug 修復:
- 修復 circuit_breaker.py get_status() 死鎖問題
- 修復 health_routes.py 模組匯入路徑錯誤

新增依賴:psutil (Worker 狀態監控)
測試覆蓋:59 個新增測試案例

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 08:14:42 +08:00
beabigegg
c11b13a7e3 fix: 修復 /health 端點瀏覽器快取導致前端顯示過時更新時間
- 後端 /health 端點加入 Cache-Control no-cache 標頭
- 前端 fetch 呼叫加入 cache: 'no-store' 選項
- 修復 portal.html 無效的 timeout 選項

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 19:17:19 +08:00
beabigegg
c034985e07 feat: 設備即時概況頁面加入 visibility 自動刷新
- 切回頁面時立即刷新資料(visibilitychange 事件)
- Tab 隱藏時跳過自動刷新,節省資源
- 加入 console.log 追蹤刷新觸發時機

與 WIP Overview 頁面行為一致。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 19:06:26 +08:00
beabigegg
5517e5f767 fix: 新增分佈式鎖防止多 Worker 同時更新快取
多個 Gunicorn workers 同時執行快取更新會導致資料庫連接競爭,
造成 F5 重新整理時前端卡住。

變更內容:
- redis_client.py: 新增 try_acquire_lock/release_lock 函數
- cache_updater.py: WIP 與 Resource 快取更新加入分佈式鎖
- realtime_equipment_cache.py: 設備狀態快取更新加入分佈式鎖

鎖機制採用 Redis SET NX EX 原子操作,fail-open 設計確保
Redis 故障時不會阻塞正常操作。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 18:50:02 +08:00
beabigegg
d5aa2fa749 perf: 為設備快取加入 Process-Level Cache 防止 GIL 競爭
- 為 resource_cache 和 realtime_equipment_cache 加入 30 秒 TTL 的進程級快取
- 使用 Double-Check Locking 確保只有一個執行緒解析 JSON
- 背景同步更新 Redis 時主動清除進程級快取
- 修復測試以清除進程級快取避免測試干擾

解決 F5 刷新設備即時概況頁面時因併發 JSON 解析導致的卡頓問題

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 18:19:30 +08:00
beabigegg
373a1f0f0e perf: 移除舊版 resource summary API 並加入 WIP DataFrame 記憶體快取
問題診斷:
- 舊版 /api/resource/summary API 使用慢速 SQL (JOIN + ROW_NUMBER),導致 55s 逾時
- 壓力測試持續呼叫此 API,佔滿所有 worker threads
- 每次 WIP API 請求都解析 14.8MB JSON,8 個並發請求造成 GIL 競爭

變更內容:
- 移除舊版 /api/resource/summary 路由和 query_resource_status_summary 函數
- 刪除未使用的 status_summary.sql
- 更新壓力測試和整合測試使用新版 /api/resource/status/summary
- 加入 ProcessLevelCache 類別實作 process-level DataFrame 快取 (30s TTL)
- 使用 double-check locking 確保只有一個 thread 解析 JSON

效能改善:
- 新版 API 使用 Redis 三層快取,回應時間 < 100ms
- Process-level 快取避免重複解析 14MB JSON,大幅改善並發效能

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 18:00:41 +08:00
beabigegg
de38959568 docs: 更新 README 並封存 sql-query-management-refactor 提案
- 更新 README.md 反映目前開發狀態 (v3.0)
  - 新增設備狀態監控、設備歷史查詢功能說明
  - 新增 Redis 快取系統、SQL 查詢安全架構狀態
  - 擴展專案結構說明,展示 sql/ 模組細節
  - 新增 Redis 環境需求與設定說明
  - 補充 2026-01-29 ~ 2026-02-03 變更日誌
- 封存 sql-query-management-refactor 至 archive/2026-02-03-
- 同步 3 個新 specs 至主目錄 (sql-loader, query-builder, common-filters)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 16:40:01 +08:00
beabigegg
f36e55e8a1 refactor: 重構 SQL 查詢管理架構,提升安全性與效能
- 新增 sql 模組:SQLLoader (LRU 快取)、QueryBuilder (參數化查詢)、CommonFilters (共用篩選器)
- 將 18 個內嵌 SQL 抽取至獨立 .sql 檔案 (dashboard, resource, wip, resource_history)
- 修復 SQL 注入漏洞:所有使用者輸入改用 Oracle bind variables (:param)
- 優化 dashboard KPI 與 workcenter_cards 端點,從 55 秒超時降至 0.1-0.16 秒
- 標記 utils.py 舊函數為 deprecated,保持向下相容
- 新增 51 個 SQL 模組單元測試,全部通過

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 16:32:19 +08:00
beabigegg
c3899c4593 fix: 修復 Excel 批次查詢的表名驗證支援 schema.table 格式
原本的正則表達式不支援帶 schema 前綴的表名(如 DWH.DW_MES_LOTMATERIALSHISTORY),
導致查詢失敗並顯示「無效的資料表名稱」錯誤。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 20:29:02 +08:00