Avoid heavy overview SQL on PChome review page
All checks were successful
CD Pipeline / deploy (push) Successful in 1m20s
All checks were successful
CD Pipeline / deploy (push) Successful in 1m20s
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
================================================================================
|
||||
|
||||
【已完成】
|
||||
- V10.446 修正 PChome 覆核頁輕量路徑的 overview timeout:覆核頁總覽改讀已存在的 shared dashboard cache / stale cache,沒有快取時只用目前覆核頁資料補足狀態,不再現場跑 `_load_competitor_decision_overview(session)` 的重型後備 SQL。
|
||||
- V10.445 補 PChome 覆核頁輕量渲染路徑:`filter=pchome_review` 不再先建完整 Dashboard `unique_items`,改為只查覆核當頁 50 筆商品、當前價、昨日價與週前價,再沿用同一張新版表格與人工覆核按鈕;降低核心比價覆核頁的全站資料負載。
|
||||
- V10.444 瘦身 PChome 覆核頁查詢:`fetch_competitor_review_queue_page()` 將覆核隊列總數與當頁資料合併在單一 SQL 內取回,避免 `/?filter=pchome_review` 為 count/page 重複掃 `latest_momo`、`latest_attempt`、`valid_competitor` CTE;保留狀態分流、人工覆核與正式價格寫入保護不變。
|
||||
- V10.443 補 PChome rescore 人工覆核入隊:`audit_competitor_match_attempt_rescore.py --apply-accepted` 只追加 `rescore_accepted_current` attempt 進人工覆核隊列,不直接寫 `competitor_prices` / `competitor_price_history`;商品看板新增「重算可採用」分流與狀態文案,讓可救回候選先由人審確認再正式更新價差。
|
||||
|
||||
@@ -325,7 +325,7 @@ YOUTUBE_API_KEY = os.getenv('YOUTUBE_API_KEY', '')
|
||||
# ==========================================
|
||||
# 系統版本與路徑
|
||||
# ==========================================
|
||||
SYSTEM_VERSION = "V10.445"
|
||||
SYSTEM_VERSION = "V10.446"
|
||||
LOG_FILE_PATH = os.path.join(BASE_DIR, 'logs/system.log')
|
||||
public_url = PUBLIC_URL # 用於模板顯示
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
> **最後更新**: 2026-05-24 (台北時間)
|
||||
> **狀態**: 🟢 四 AI Agent 自動化閉環已落地;LLM 路由紅線升級為 Ollama-first 三主機級聯,Gemini 備援預設關閉
|
||||
> **適用版本**: V10.445
|
||||
> **適用版本**: V10.446
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
## 📅 詳細更新日誌 (考古存檔)
|
||||
|
||||
### 2026-05-24:PChome 近門檻身份回收第二輪
|
||||
- **V10.446 PChome 覆核頁 overview timeout 修正**: 覆核頁輕量 render path 的總覽改讀既有 shared dashboard cache / stale cache;若快取不存在,只用目前覆核頁資料補足 review count 與狀態分流,不再即時呼叫 `_load_competitor_decision_overview(session)` 的重型 SQL,避免正式資料量下 statement timeout。
|
||||
- **V10.445 PChome 覆核頁輕量渲染路徑**: `filter=pchome_review` 直接走覆核隊列專用 render path,不再先建完整 Dashboard `unique_items`;當頁只查 50 筆覆核 SKU 的商品資料、最新價、昨日價與週前價,仍沿用同一張新版表格、狀態分流、PChome 候選說明與人工覆核按鈕,降低核心比價覆核頁的全站資料負載。
|
||||
- **V10.444 PChome 覆核頁查詢瘦身**: `fetch_competitor_review_queue_page()` 將原本 count + page 兩次重跑 review CTE 改成單次 SQL 的 `total_rows` + `paged_rows` 查詢,同步取得總數與頁面資料,降低 `/?filter=pchome_review` 對 `latest_momo` / `latest_attempt` / `valid_competitor` 的重複掃描;正式站小批次 rescore 入隊後,用於維持核心比價覆核頁可操作速度。
|
||||
- **V10.443 PChome rescore 人工覆核入隊**: `scripts/audit_competitor_match_attempt_rescore.py --apply-accepted` 只會把最新版 matcher 已通過門檻的舊低信心候選追加為 `rescore_accepted_current` attempt,進入商品看板人工覆核隊列;不寫 `competitor_prices`、不寫 `competitor_price_history`,必須由操作員按「採用同款」後才正式更新 PChome 價差。Dashboard 補上「重算可採用待審」分流與狀態文案,避免安全回刷候選混在一般低信心項目裡。
|
||||
|
||||
@@ -1644,6 +1644,51 @@ def _enrich_dashboard_items_for_competitor_review(session, paged_items, review_q
|
||||
return paged_items
|
||||
|
||||
|
||||
def _load_cached_competitor_overview_for_review(now_taipei, review_queue, review_queue_total, review_status):
|
||||
full_data = None
|
||||
cached_data = _DASHBOARD_DATA_CACHE.get('full_data')
|
||||
cached_ts = _DASHBOARD_DATA_CACHE.get('full_timestamp')
|
||||
if cached_data and cached_ts and now_taipei.timestamp() - cached_ts < _DASHBOARD_STALE_CACHE_MAX_AGE:
|
||||
full_data = cached_data
|
||||
if not full_data:
|
||||
full_data = _load_shared_full_dashboard_cache(now_taipei) or _load_stale_full_dashboard_cache(now_taipei)
|
||||
|
||||
overview = dict((full_data or {}).get('competitor_overview') or {})
|
||||
if not overview:
|
||||
overview = {
|
||||
'total_active': 0,
|
||||
'matched_count': 0,
|
||||
'match_rate': 0,
|
||||
'pchome_advantage_count': 0,
|
||||
'momo_threat_count': 0,
|
||||
'near_count': 0,
|
||||
'pending_match_count': 0,
|
||||
'ai_pick_count': 0,
|
||||
'avg_advantage_gap': 0,
|
||||
'last_pchome_crawled': None,
|
||||
'top_picks': [],
|
||||
'top_pchome_advantages': [],
|
||||
'top_momo_threats': [],
|
||||
'pending_priority': [],
|
||||
'review_queue': [],
|
||||
'review_status_counts': {},
|
||||
}
|
||||
|
||||
status_counts = dict(overview.get('review_status_counts') or {})
|
||||
status_counts['all'] = max(int(status_counts.get('all') or 0), int(review_queue_total or 0))
|
||||
if review_status and review_status != 'all':
|
||||
status_counts[review_status] = max(int(status_counts.get(review_status) or 0), int(review_queue_total or 0))
|
||||
overview['review_status_counts'] = status_counts
|
||||
overview['review_queue_count'] = max(
|
||||
int(overview.get('review_queue_count') or 0),
|
||||
int(review_queue_total or 0),
|
||||
)
|
||||
if not overview.get('review_queue'):
|
||||
overview['review_queue'] = list(review_queue[:3])
|
||||
overview.setdefault('unit_comparable_count', 0)
|
||||
return overview
|
||||
|
||||
|
||||
def _render_pchome_review_dashboard(
|
||||
session,
|
||||
*,
|
||||
@@ -1677,7 +1722,12 @@ def _render_pchome_review_dashboard(
|
||||
paged_items = _build_review_dashboard_items(session, review_queue, today_start_db)
|
||||
_enrich_dashboard_items_for_competitor_review(session, paged_items, review_queue_map)
|
||||
|
||||
competitor_overview = _load_competitor_decision_overview(session)
|
||||
competitor_overview = _load_cached_competitor_overview_for_review(
|
||||
now_taipei,
|
||||
review_queue,
|
||||
review_queue_total,
|
||||
review_status,
|
||||
)
|
||||
review_status_options = _build_review_status_options(competitor_overview)
|
||||
total_pages = math.ceil(review_queue_total / per_page) if review_queue_total else 0
|
||||
total_products_history = int(competitor_overview.get('total_active') or 0)
|
||||
|
||||
@@ -136,6 +136,8 @@ def test_dashboard_v2_is_production_default_and_uses_real_dashboard_data():
|
||||
assert "def _render_pchome_review_dashboard(" in route_source
|
||||
assert "return _render_pchome_review_dashboard(" in route_source
|
||||
assert "_build_review_dashboard_items(session, review_queue, today_start_db)" in route_source
|
||||
assert "_load_cached_competitor_overview_for_review(" in route_source
|
||||
assert "_load_competitor_decision_overview(session)" not in route_source
|
||||
assert "只替 PChome 覆核當頁建立商品列" in route_source
|
||||
assert "_load_competitor_decision_overview(session, unique_items)" in route_source
|
||||
assert "item_map = {}" in route_source
|
||||
|
||||
Reference in New Issue
Block a user