fix: 修复统计日历 bootstrap 导致整站 500

日历数据改为安全 JSON 内嵌,仅统计页构建;构建失败时降级为空,避免拖垮其他页面。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-30 09:24:54 +08:00
parent 3b687d17eb
commit 32079bb4c2
12 changed files with 91 additions and 35 deletions
+23
View File
@@ -1,6 +1,7 @@
"""按交易日聚合实例 trade_records 盈亏,供统计分析页日历 API 使用。"""
from __future__ import annotations
import json
from datetime import datetime, timedelta
from typing import Any, Callable
@@ -90,3 +91,25 @@ def build_initial_stats_calendar(
row_matches_fn,
reset_hour=reset_hour,
)
def build_stats_calendar_bootstrap(
pnls: list[tuple],
now_dt: datetime,
row_matches_fn: Callable[[Any, str], bool],
*,
reset_hour: int = 8,
segment_key: str = "all",
) -> tuple[dict[str, Any] | None, str | None]:
"""返回 (payload, json_str);失败时 (None, None),供模板安全内嵌。"""
try:
payload = build_initial_stats_calendar(
pnls,
now_dt,
row_matches_fn,
reset_hour=reset_hour,
segment_key=segment_key,
)
return payload, json.dumps(payload, ensure_ascii=False, separators=(",", ":"))
except Exception:
return None, None