账本:按来源运行找出具过的正式运行、对过的账改在 SQL 里按 origin.source_run 筛

为什么:GET 账本每次都要列这两样,原来把全部 ledger_issue / reconcile 运行读出来在 Python 里筛,出具多了就是整表扫。改成 origin_kind(有索引)加 json_extract(origin, "$.source_run"),写法同 auth/keys 认幂等键。
This commit is contained in:
ThearchyHelios
2026-10-16 17:11:55 +08:00
parent 538799e70d
commit 5e9413e080
2 changed files with 12 additions and 5 deletions
+6 -3
View File
@@ -144,9 +144,12 @@ async def issued_today(session: Any) -> int:
async def issued_runs(session: Any, run_id: str) -> list[Run]:
"""这次运行按口径出具过的正式运行(origin.source_run 是它),新的在前。origin_kind 有索引,先按它筛再看 origin。"""
rows = (await session.execute(select(Run).where(Run.origin_kind == ORIGIN).order_by(Run.created_at.desc()))).scalars()
return [r for r in rows if isinstance(r.origin, dict) and r.origin.get("source_run") == run_id]
"""这次运行按口径出具过的正式运行(origin.source_run 是它),新的在前。origin_kind 有索引,先按它筛再看 origin
(json_extract,同 auth/keys 认幂等键的写法)。"""
rows = (await session.execute(select(Run).where(
Run.origin_kind == ORIGIN, func.json_extract(Run.origin, "$.source_run") == run_id)
.order_by(Run.created_at.desc()))).scalars()
return list(rows)
def issued_view(run: Run) -> dict[str, Any]:
+6 -2
View File
@@ -131,8 +131,12 @@ def actions_of(content: dict[str, Any], names: dict[str, str], hide: Any = None)
async def reconciled_runs(session: Any, run_id: str) -> list[Run]:
"""对这次运行对过的账(origin.source_run 是它),新的在前。"""
rows = (await session.execute(select(Run).where(Run.origin_kind == ORIGIN).order_by(Run.created_at.desc()))).scalars()
return [r for r in rows if isinstance(r.origin, dict) and r.origin.get("source_run") == run_id]
from sqlalchemy import func
rows = (await session.execute(select(Run).where(
Run.origin_kind == ORIGIN, func.json_extract(Run.origin, "$.source_run") == run_id)
.order_by(Run.created_at.desc()))).scalars()
return list(rows)
def reconciled_view(run: Run) -> dict[str, Any]: