fix(dashboard): avoid redundant prewarm rebuilds
All checks were successful
CD Pipeline / deploy (push) Successful in 2m15s

This commit is contained in:
OoO
2026-05-01 16:36:58 +08:00
parent 2ac7410d40
commit e86075d59d
4 changed files with 6 additions and 5 deletions

4
app.py
View File

@@ -95,8 +95,8 @@ except Exception as e:
sys_log.error(f"無法檢測磁碟空間: {e}")
# 🚩 系統版本定義 (備份與顯示用)
# 🚩 2026-05-01 V10.65: Prewarm dashboard cache and expose AI pick evidence gaps
SYSTEM_VERSION = "V10.65"
# 🚩 2026-05-01 V10.66: Avoid redundant dashboard prewarm rebuilds across workers
SYSTEM_VERSION = "V10.66"
# ==========================================
# 🔒 SQL Injection 防護函數

View File

@@ -254,7 +254,7 @@ YOUTUBE_API_KEY = os.getenv('YOUTUBE_API_KEY', '')
# ==========================================
# 系統版本與路徑
# ==========================================
SYSTEM_VERSION = "V10.65"
SYSTEM_VERSION = "V10.66"
LOG_FILE_PATH = os.path.join(BASE_DIR, 'logs/system.log')
public_url = PUBLIC_URL # 用於模板顯示

View File

@@ -605,10 +605,10 @@ def _write_shared_full_dashboard_cache(full_data):
pass
def warm_full_dashboard_cache(reason='manual'):
def warm_full_dashboard_cache(reason='manual', force_rebuild=False):
"""供 API、排程與 Gunicorn worker 啟動時預熱商品看板完整快取。"""
started = time.time()
data = get_full_dashboard_data(force_rebuild=True)
data = get_full_dashboard_data(force_rebuild=force_rebuild)
duration_ms = (time.time() - started) * 1000
sys_log.info(
f"[Dashboard] [Cache] ✅ 預熱完成 | reason={reason} | "

View File

@@ -51,6 +51,7 @@ def test_dashboard_v2_is_production_default_and_uses_real_dashboard_data():
assert "_load_stale_full_dashboard_cache(now)" in route_source
assert "_write_shared_full_dashboard_cache(full_data)" in route_source
assert "warm_full_dashboard_cache" in route_source
assert "force_rebuild=False" in route_source
assert "_load_competitor_decision_overview(session)" in route_source
assert "ai_price_recommendations" in route_source
assert "pending_match_count" in route_source