修复复盘列表先读缓存再后台同步,避免模拟盘握库卡死加载。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -275,7 +275,16 @@ def register_options_review_routes(app: Flask, cfg: dict[str, Any], repo_root: s
|
||||
ex, _err = _require_ex(cfg)
|
||||
result = ensure_local_review_synced(conn, ex=ex if ex is not None else None)
|
||||
conn.commit()
|
||||
return jsonify(result)
|
||||
if isinstance(result, dict) and result.get("ok") is not False:
|
||||
result["ok"] = True
|
||||
return jsonify(result if isinstance(result, dict) else {"ok": True, "result": result})
|
||||
except Exception as e:
|
||||
print(f"[options_review_sync] {e}", flush=True)
|
||||
try:
|
||||
conn.rollback()
|
||||
except Exception:
|
||||
pass
|
||||
return jsonify({"ok": False, "msg": f"同步失败: {e}"}), 500
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
@@ -284,16 +293,21 @@ def register_options_review_routes(app: Flask, cfg: dict[str, Any], repo_root: s
|
||||
def api_options_review_trades():
|
||||
conn = cfg["get_db"]()
|
||||
try:
|
||||
# 翻页可跳过同步,仅刷新当前卡片列表
|
||||
do_sync = (request.args.get("sync") or "1").strip().lower() not in (
|
||||
"0",
|
||||
"false",
|
||||
"no",
|
||||
# 默认不同步:列表先读缓存;完整同步走 POST /api/options/review/sync
|
||||
do_sync = (request.args.get("sync") or "0").strip().lower() in (
|
||||
"1",
|
||||
"true",
|
||||
"yes",
|
||||
)
|
||||
if do_sync:
|
||||
try:
|
||||
ex, _err = _require_ex(cfg)
|
||||
ensure_local_review_synced(conn, ex=ex if ex is not None else None)
|
||||
# 列表路径不做历史回填,避免模拟盘握库二次开连接卡死
|
||||
ensure_local_review_synced(
|
||||
conn,
|
||||
ex=ex if ex is not None else None,
|
||||
backfill_exchange_pnl=False,
|
||||
)
|
||||
conn.commit()
|
||||
except Exception as sync_err:
|
||||
# 同步撞锁时仍返回已有列表,避免整页 500
|
||||
@@ -303,6 +317,8 @@ def register_options_review_routes(app: Flask, cfg: dict[str, Any], repo_root: s
|
||||
except Exception:
|
||||
pass
|
||||
init_options_review_tables(conn)
|
||||
else:
|
||||
init_options_review_tables(conn)
|
||||
filt = dict(
|
||||
source_type=_review_source_for_mode(request.args.get("source_type")),
|
||||
underlying=(request.args.get("underlying") or "").strip() or None,
|
||||
|
||||
Reference in New Issue
Block a user