From 0b57fff6c83b34b7adb39811ffd69c915edc54d2 Mon Sep 17 00:00:00 2001 From: Abdul Basit Date: Mon, 2 Oct 2023 23:25:49 +0500 Subject: [PATCH] Fix update query for incrementing collection supply --- api/src/background_worker/worker.rs | 3 +-- api/src/mutations/mint.rs | 15 +++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/api/src/background_worker/worker.rs b/api/src/background_worker/worker.rs index a021e74..32cad80 100644 --- a/api/src/background_worker/worker.rs +++ b/api/src/background_worker/worker.rs @@ -86,8 +86,7 @@ where }, }; - let Some(model) = model - else { + let Some(model) = model else { error!("Job tracking not found"); return; }; diff --git a/api/src/mutations/mint.rs b/api/src/mutations/mint.rs index 733373b..7af2012 100644 --- a/api/src/mutations/mint.rs +++ b/api/src/mutations/mint.rs @@ -885,13 +885,16 @@ impl Mutation { .all(conn) .await?; - let tx = conn.begin().await?; - - let mut collection_am: collections::ActiveModel = collection_model.clone().into(); + let tx: sea_orm::DatabaseTransaction = conn.begin().await?; - collection_am.supply = Set(collection_model.supply.map(|supply| supply.add(1))); - - collection_am.update(&tx).await?; + collections::Entity::update_many() + .col_expr( + collections::Column::Supply, + Expr::value(Expr::col(collections::Column::Supply).add(Value::Int(Some(1)))), + ) + .filter(collections::Column::Id.eq(collection_model.id)) + .exec(&tx) + .await?; let mint = collection_mints::ActiveModel { collection_id: Set(drop.collection_id),