aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2024-09-16 14:15:06 +0100
committerGravatar Chris Lovering <[email protected]>2024-09-16 14:15:49 +0100
commit0df38956baa8f9f8c7e27edc7018578bb97a61ac (patch)
treea959ea4cc80780efd11ac5b4dcab7fa0c5482074
parentAdd a gift emssage to the order (diff)
Reduce the time voucher rows are locked when creating orders
-rw-r--r--thallium-backend/src/routes/orders.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/thallium-backend/src/routes/orders.py b/thallium-backend/src/routes/orders.py
index af659bd..f52a2f9 100644
--- a/thallium-backend/src/routes/orders.py
+++ b/thallium-backend/src/routes/orders.py
@@ -21,8 +21,6 @@ async def create_order(request: Request, db: DBSession, client: PrintfulClient,
If the voucher does not have enough funds, the order is cancelled.
"""
voucher: Voucher = request.state.voucher
- stmt = select(DBVoucher).where(DBVoucher.id == voucher.id).with_for_update()
- db_voucher = await db.scalar(stmt)
resp = await client.post(
"/orders/estimate-costs",
@@ -31,6 +29,9 @@ async def create_order(request: Request, db: DBSession, client: PrintfulClient,
)
resp.raise_for_status()
cost = OrderCosts.model_validate(resp.json()["result"]["costs"])
+
+ stmt = select(DBVoucher).where(DBVoucher.id == voucher.id).with_for_update()
+ db_voucher = await db.scalar(stmt)
if cost.total > db_voucher.balance:
raise HTTPException(
status_code=400,