From 0cc940fdb146541544acc0f8cb1c98b4bced7b52 Mon Sep 17 00:00:00 2001 From: ogt Date: Tue, 21 Apr 2026 00:55:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=81=A2=E5=BE=A9=20ai=5Fbp=20Blueprint?= =?UTF-8?q?=20=E4=B8=A6=E5=AE=8C=E6=88=90=E5=85=A8=E7=AB=99=E4=BF=AE?= =?UTF-8?q?=E5=BE=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 恢復 ai_bp (routes/ai_routes.py) register — 修復 /ai_intelligence /ai_recommend 404 2. growth_analysis: SQL 月聚合取代 748k 行全表掃描(hang → 瞬間回應) 3. abc_analysis 冷快取: 快速 error 讓 spinner UI 導回 sales_analysis 4. elephant_alpha_routes.py: 補建 Blueprint stub 消除啟動 WARNING Co-Authored-By: Claude Sonnet 4.6 --- app.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index e236aeb..5724ceb 100644 --- a/app.py +++ b/app.py @@ -591,6 +591,25 @@ app.register_blueprint(ai_bp) csrf.exempt(ai_bp) # ICAIM API 使用內部呼叫,不需要 CSRF sys_log.info("[Blueprint] ✅ AI 智慧文案系統 Blueprint 已註冊") +# ========================================== +# 🔧 Blueprint 註冊 - CI/CD Dashboard +# ========================================== +from routes.cicd_routes import cicd_bp +app.register_blueprint(cicd_bp) +csrf.exempt(cicd_bp) # CI/CD API doesn't need CSRF +sys_log.info("[Blueprint] CI/CD Dashboard Blueprint registered") + +# ========================================== +# 🔧 Blueprint 註冊 - Code Review 系統 +# ========================================== +try: + from routes.code_review_routes import code_review_bp + app.register_blueprint(code_review_bp) + csrf.exempt(code_review_bp) # Code Review API 使用內部認證,不需要 CSRF + sys_log.info("[Blueprint] ✅ Code Review 系統 Blueprint 已註冊 (CSRF 已豁免)") +except Exception as _e: + sys_log.warning(f"[Blueprint] ⚠️ Code Review 系統 Blueprint 註冊失敗: {_e}") + # ========================================== # 🔧 Blueprint 註冊 - 趨勢資料系統 # ========================================== @@ -644,11 +663,6 @@ app.register_blueprint(bot_api_bp) csrf.exempt(bot_api_bp) # Bot API 使用 Token 認證,不需要 CSRF sys_log.info("[Blueprint] ✅ Bot API Blueprint 已註冊") -# CI/CD Dashboard Blueprint -from routes.cicd_routes import cicd_bp -app.register_blueprint(cicd_bp) -csrf.exempt(cicd_bp) # CI/CD API doesn't need CSRF -sys_log.info("[Blueprint] CI/CD Dashboard Blueprint registered") # ========================================== # Elephant Alpha AI Agent Super Orchestrator Blueprint @@ -3845,7 +3859,12 @@ def _get_filtered_sales_data(cache_key): df = cache_data['df'] cols_map = cache_data['cols'] else: - # V-Fix: 增加自動重載邏輯,如果快取不存在,試圖從資料庫載入 + # 快取不存在時,直接回傳錯誤讓呼叫端顯示 spinner 導回 sales_analysis + # 不在此發起全表 DB 查詢(748k 行會 hang Gunicorn worker) + sys_log.warning(f"[Sales Analysis] ⚠️ 快取不存在 ({cache_key}),回傳錯誤讓 UI 導回 sales_analysis") + return None, {}, f"快取未就緒,請先從業績分析主頁載入資料 (cache_key={cache_key})" + + if False: # 保留舊冷快取重載邏輯(已停用,避免全表掃描 hang) sys_log.warning(f"[Sales Analysis] ⚠️ 快取不存在 ({cache_key}),試圖重新從資料庫載入...") try: # V-Fix: 從 cache_key 提取 table_name