修复:消除使用幂等缺失键间隙锁

This commit is contained in:
焦龙言
2026-07-26 22:34:46 +08:00
parent 33228faffc
commit cda87a4d65
4 changed files with 291 additions and 100 deletions
@@ -132,12 +132,8 @@ class OperationDao:
key_column: InstrumentedAttribute,
idempotency_key: str,
*extra_conditions: ColumnElement[bool],
for_update: bool = False,
) -> Any | None:
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)
result = await db.execute(select(model).where(key_column == idempotency_key, *extra_conditions))
return result.scalar_one_or_none()
@staticmethod
@@ -377,8 +373,6 @@ 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,
@@ -386,7 +380,6 @@ class OperationDao:
BizUsageRecord.idempotency_key,
idempotency_key,
*cls._usage_scope_conditions(site_ids),
for_update=for_update,
)
@classmethod