代码提交
This commit is contained in:
1 parent
70da7c5649
commit
178572bc7f
79 files changed
+13456
-798
No files matched your search
+44
@@ -195,6 +195,50 @@ class DeepResearchSessionRepository:
|
||||
).scalar_one_or_none()
|
||||
return self._row_to_dict(row) if row else None
|
||||
|
||||
async def replace_report_if_unchanged(
|
||||
self,
|
||||
session_id: str,
|
||||
*,
|
||||
expected_report: str,
|
||||
report_markdown: str,
|
||||
user_id: str | _AutoSentinel = AUTO,
|
||||
) -> dict[str, Any] | None:
|
||||
"""Atomically replace a report only when its exact prior text still matches.
|
||||
|
||||
The caller may use a hash for user-facing diagnostics, but SQL compares
|
||||
the text itself so another request cannot slip in between a Python-side
|
||||
hash check and the update.
|
||||
"""
|
||||
resolved = resolve_user_id(
|
||||
user_id,
|
||||
method_name="DeepResearchSessionRepository.replace_report_if_unchanged",
|
||||
)
|
||||
async with self._sf() as session:
|
||||
clauses = [
|
||||
DeepResearchSessionRow.id == session_id,
|
||||
DeepResearchSessionRow.report_markdown == expected_report,
|
||||
]
|
||||
if resolved is not None:
|
||||
clauses.append(DeepResearchSessionRow.user_id == resolved)
|
||||
result = await session.execute(
|
||||
update(DeepResearchSessionRow)
|
||||
.where(*clauses)
|
||||
.values(
|
||||
report_markdown=report_markdown,
|
||||
report_html=None,
|
||||
updated_at=datetime.now(UTC),
|
||||
)
|
||||
)
|
||||
if result.rowcount == 0:
|
||||
return None
|
||||
await session.commit()
|
||||
row = (
|
||||
await session.execute(
|
||||
select(DeepResearchSessionRow).where(DeepResearchSessionRow.id == session_id)
|
||||
)
|
||||
).scalar_one_or_none()
|
||||
return self._row_to_dict(row) if row else None
|
||||
|
||||
# ── delete ──────────────────────────────────────────────────────────────
|
||||
|
||||
async def delete(
|
||||
|
||||
Reference in new issue
Block a user