Skip to content

Commit

Permalink
Small optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrug committed Dec 9, 2024
1 parent e252f0e commit eaa203c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions crates/orderbook/src/orderbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,18 @@ impl Orderbook {
self.replace_order(order, old_order, quote).await
} else {
let quote_id = quote.as_ref().and_then(|quote| quote.id);
let order_uid = order.metadata.uid;

self.database
.insert_order(&order, quote.clone())
.await
.map_err(|err| AddOrderError::from_insertion(err, &order))?;
Metrics::on_order_operation(
&OrderWithQuote::try_new(order.clone(), quote)?,
&OrderWithQuote::try_new(order, quote)?,
OrderOperation::Created,
);

Ok((order.metadata.uid, quote_id))
Ok((order_uid, quote_id))
}
}

Expand Down Expand Up @@ -407,6 +408,7 @@ impl Orderbook {
}

let quote_id = quote.as_ref().and_then(|quote| quote.id);
let order_uid = validated_new_order.metadata.uid;

self.database
.replace_order(
Expand All @@ -418,11 +420,11 @@ impl Orderbook {
.map_err(|err| AddOrderError::from_insertion(err, &validated_new_order))?;
Metrics::on_order_operation(&old_order, OrderOperation::Cancelled);
Metrics::on_order_operation(
&OrderWithQuote::try_new(validated_new_order.clone(), quote)?,
&OrderWithQuote::try_new(validated_new_order, quote)?,
OrderOperation::Created,
);

Ok((validated_new_order.metadata.uid, quote_id))
Ok((order_uid, quote_id))
}

pub async fn get_order(&self, uid: &OrderUid) -> Result<Option<Order>> {
Expand Down

0 comments on commit eaa203c

Please sign in to comment.