From fa57386c06441a40cb65817a1f3856db95c2bb79 Mon Sep 17 00:00:00 2001 From: ArielBlanco Date: Fri, 7 Oct 2022 09:12:09 +0000 Subject: [PATCH] Update FindManyWithCache Method --- .../Catalog/ProductRepository.cs | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/Libraries/Hotcakes.Commerce/Catalog/ProductRepository.cs b/Libraries/Hotcakes.Commerce/Catalog/ProductRepository.cs index 81df41722..5fd400148 100644 --- a/Libraries/Hotcakes.Commerce/Catalog/ProductRepository.cs +++ b/Libraries/Hotcakes.Commerce/Catalog/ProductRepository.cs @@ -519,33 +519,31 @@ public List FindMany(IEnumerable productBvins) public List FindManyWithCache(IEnumerable productBvins) { + var result = new List(); var cachedProducts = new List(); - var needsRetrieval = new List(); + foreach (var productBvin in productBvins) { var product = CacheManager.GetProduct(productBvin, Context.CurrentStore.Id, Context.MainContentCulture); if (product != null) + { cachedProducts.Add(product); + } else - needsRetrieval.Add(productBvin); - } - var retrievedProducts = FindMany(needsRetrieval); - retrievedProducts.ForEach(p => CacheManager.AddProduct(p)); + { + Find(productBvin); + var lastAddProduct = CacheManager.GetProduct(productBvin, Context.CurrentStore.Id, Context.MainContentCulture); + if (lastAddProduct != null) + { + cachedProducts.Add(lastAddProduct); + } + } - var result = new List(); - foreach (var productBvin in productBvins) - { var cached = cachedProducts.Where(p => p.Bvin == productBvin).FirstOrDefault(); if (cached != null) { result.Add(cached); } - else - { - var retrieved = retrievedProducts.Where(p => p.Bvin == productBvin).FirstOrDefault(); - if (retrieved != null) - result.Add(retrieved); - } } return result; }