Files
DashBoard/openspec/changes/historical-query-slow-connection/proposal.md
egg 71c8102de6 feat: dataset cache for hold/resource history + slow connection migration
Two changes combined:

1. historical-query-slow-connection: Migrate all historical query pages
   to read_sql_df_slow with semaphore concurrency control (max 3),
   raise DB slow timeout to 300s, gunicorn timeout to 360s, and
   unify frontend timeouts to 360s for all historical pages.

2. hold-resource-history-dataset-cache: Convert hold-history and
   resource-history from multi-query to single-query + dataset cache
   pattern (L1 ProcessLevelCache + L2 Redis parquet/base64, TTL=900s).
   Replace old GET endpoints with POST /query + GET /view two-phase
   API. Frontend auto-retries on 410 cache_expired.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 13:15:02 +08:00

43 lines
2.6 KiB
Markdown
Raw 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.

## Why
歷史查詢頁面reject-history、query-tool、hold-history、resource-history、job-query、excel-query、mid-section-defect
目前共用 connection pool 的 55s `call_timeout`,前端也設有 60~120s AbortController timeout。
大範圍查詢(如長日期區間或大量 LOT經常逼近或超過 timeout使用者看到 "signal is aborted without reason" 錯誤。
歷史查詢屬於使用者手動觸發、非即時、可等待的操作,應採用獨立連線(`read_sql_df_slow`)配合
semaphore 並行控制,以「用時間換結果」的方式完成查詢,同時保護 connection pool 不被耗盡。
## What Changes
- 歷史查詢 service 從 `read_sql_df`pool, 55s遷移到 `read_sql_df_slow`(獨立連線, 300s
- `read_sql_df_slow` 加入 global semaphore 限制並行數(預設 3避免耗盡 Oracle 連線
- `read_sql_df_slow` 的 timeout 預設從寫死 120s 改為 config 驅動(預設 300s
- Gunicorn worker timeout 從 130s 提升到 360s 以容納長查詢
- 前端歷史頁 timeout 統一提升到 360s6 分鐘)
- 新增 `DB_SLOW_CALL_TIMEOUT_MS``DB_SLOW_MAX_CONCURRENT` 環境變數設定
- 即時監控頁wip、hold-overview、resource-status 等)完全不受影響
## Capabilities
### New Capabilities
- `slow-query-concurrency-control`: `read_sql_df_slow` 的 semaphore 並行控制與 config 驅動 timeout
### Modified Capabilities
- `reject-history-api`: 底層 DB 查詢從 pooled 改為 dedicated slow connection
- `hold-history-api`: 底層 DB 查詢從 pooled 改為 dedicated slow connection
- `query-tool-lot-trace`: 移除 `read_sql_df_slow` 寫死的 120s timeout改用 config 預設
- `reject-history-page`: 前端 API_TIMEOUT 從 60s 提升到 360s
- `hold-history-page`: 前端 API_TIMEOUT 從 60s 提升到 360s
- `resource-history-page`: 前端 API_TIMEOUT 從 60s 提升到 360s後端遷移至 slow connection
- `query-tool-equipment`: 前端 timeout 從 120s 提升到 360s
- `progressive-trace-ux`: DEFAULT_STAGE_TIMEOUT_MS 從 60s 提升到 360s
## Impact
- **後端 services**reject_history_service、reject_dataset_cache、hold_history_service、resource_history_service、job_query_service、excel_query_service、query_tool_service
- **核心模組**database.pysemaphore + config、settings.py新設定、gunicorn.conf.pytimeout
- **前端頁面**reject-history、mid-section-defect、hold-history、resource-history、query-tool5 個 composable + 1 component、job-query、excel-query
- **不影響**即時監控頁wip-overview、wip-detail、hold-overview、hold-detail、resource-status、admin-performance