fix: reports匹配链修正(标题匹配不再是死代码) + strategy_history空历史时降级当前行
This commit is contained in:
@@ -230,6 +230,8 @@ def api_strategy_history(code):
|
||||
LIMIT ?
|
||||
""", (code, limit)).fetchall()
|
||||
history = [dict(r) for r in rows]
|
||||
if not history:
|
||||
raise LookupError("history empty, fallback to current row")
|
||||
except Exception:
|
||||
# 表不存在或查询失败 → 降级为当前 holding_strategies 行
|
||||
history = []
|
||||
@@ -306,8 +308,11 @@ def api_reports():
|
||||
for f in sorted(reports_dir.iterdir(), reverse=True):
|
||||
if f.suffix != ".json":
|
||||
continue
|
||||
data = _load_json(f) if (cron_key or script_key) else None
|
||||
if cron_key or script_key:
|
||||
stem = f.stem
|
||||
title = str(data.get("title", ""))
|
||||
# 命中链:job id 前缀 → 名/脚本子串(文件名) → pipeline名子串(标题)
|
||||
hit = False
|
||||
if job_id and stem.startswith(f"cron_{job_id}_"):
|
||||
hit = True
|
||||
@@ -315,18 +320,12 @@ def api_reports():
|
||||
hit = True
|
||||
elif script_key and script_key in stem:
|
||||
hit = True
|
||||
elif cron_key and cron_key in title:
|
||||
hit = True
|
||||
if not hit:
|
||||
continue
|
||||
data = _load_json(f)
|
||||
# 最后兜底:pipeline名出现在报告标题里也算匹配
|
||||
if (cron_key or script_key) and cron_key:
|
||||
title = str(data.get("title", ""))
|
||||
stem = f.stem
|
||||
if not (job_id and stem.startswith(f"cron_{job_id}_")) \
|
||||
and cron_key not in stem \
|
||||
and not (script_key and script_key in stem) \
|
||||
and cron_key not in title:
|
||||
continue
|
||||
if data is None:
|
||||
data = _load_json(f)
|
||||
reports.append({
|
||||
"id": f.stem,
|
||||
"title": data.get("title", f.stem),
|
||||
|
||||
Reference in New Issue
Block a user