From 7f2a097152a0c2b73005b149c345a50c891ade93 Mon Sep 17 00:00:00 2001 From: dam-bal <94970129+dam-bal@users.noreply.github.com> Date: Thu, 27 Apr 2023 21:45:41 +0100 Subject: [PATCH 1/2] skipping non limited products Currently it checks for all products even non limited ones, and that is not how it's suppose to work --- .../Core/Cart/CheckoutCart.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/DDD.BuildingBlocks.V9.OutOfProcDependency/Core/Cart/CheckoutCart.cs b/DDD.BuildingBlocks.V9.OutOfProcDependency/Core/Cart/CheckoutCart.cs index c35de2d..6256510 100644 --- a/DDD.BuildingBlocks.V9.OutOfProcDependency/Core/Cart/CheckoutCart.cs +++ b/DDD.BuildingBlocks.V9.OutOfProcDependency/Core/Cart/CheckoutCart.cs @@ -47,6 +47,11 @@ public void SetPayment(Payment payment) */ foreach (var product in Products) { + if (!product.Product.LimitedAvailability) + { + continue; + } + var orderWithLimitedProductExistsInThisQuarter = await orderRepository.Exists( specification: new ActiveOrderWithLimitedProductThisQuarter(CustomerId, product.Product.Name), cancellationToken: CancellationToken.None); From f8c2f1e9aca1060045f088ab5ac445456e432236 Mon Sep 17 00:00:00 2001 From: dam-bal <94970129+dam-bal@users.noreply.github.com> Date: Fri, 28 Apr 2023 08:00:52 +0100 Subject: [PATCH 2/2] improvement --- .../Core/Cart/CheckoutCart.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/DDD.BuildingBlocks.V9.OutOfProcDependency/Core/Cart/CheckoutCart.cs b/DDD.BuildingBlocks.V9.OutOfProcDependency/Core/Cart/CheckoutCart.cs index 6256510..78c8548 100644 --- a/DDD.BuildingBlocks.V9.OutOfProcDependency/Core/Cart/CheckoutCart.cs +++ b/DDD.BuildingBlocks.V9.OutOfProcDependency/Core/Cart/CheckoutCart.cs @@ -40,20 +40,17 @@ public void SetPayment(Payment payment) public async Task PlaceOrder(IOrderRepository orderRepository) { + var limitedProducts = Products.Where(x => x.Product.LimitedAvailability); + /* * This is obviously a naive implementation but in same cases might yield better results * than using JOINs, since we can issue simpler queries in parallel and then * scatter and collect with Task.WhenAll(...) */ - foreach (var product in Products) + foreach (var limitedProduct in limitedProducts) { - if (!product.Product.LimitedAvailability) - { - continue; - } - var orderWithLimitedProductExistsInThisQuarter = await orderRepository.Exists( - specification: new ActiveOrderWithLimitedProductThisQuarter(CustomerId, product.Product.Name), + specification: new ActiveOrderWithLimitedProductThisQuarter(CustomerId, limitedProduct.Product.Name), cancellationToken: CancellationToken.None); if (orderWithLimitedProductExistsInThisQuarter)