修复:补强使用并发幂等复核

This commit is contained in:
焦龙言
2026-07-26 21:43:55 +08:00
parent bc774c74e6
commit 33228faffc
4 changed files with 359 additions and 13 deletions
@@ -132,8 +132,12 @@ class OperationDao:
key_column: InstrumentedAttribute,
idempotency_key: str,
*extra_conditions: ColumnElement[bool],
for_update: bool = False,
) -> Any | None:
result = await db.execute(select(model).where(key_column == idempotency_key, *extra_conditions))
statement = select(model).where(key_column == idempotency_key, *extra_conditions)
if for_update:
statement = statement.with_for_update().execution_options(populate_existing=True)
result = await db.execute(statement)
return result.scalar_one_or_none()
@staticmethod
@@ -373,6 +377,8 @@ class OperationDao:
db: AsyncSession,
idempotency_key: str,
site_ids: list[int] | None = None,
*,
for_update: bool = False,
) -> BizUsageRecord | None:
return await cls._get_by_key(
db,
@@ -380,6 +386,7 @@ class OperationDao:
BizUsageRecord.idempotency_key,
idempotency_key,
*cls._usage_scope_conditions(site_ids),
for_update=for_update,
)
@classmethod