Skip to content

Commit

Permalink
Merge pull request #414 from ArielBlanco1990/Update_FindManyWithCache…
Browse files Browse the repository at this point in the history
…_Method

Update FindManyWithCache Method
  • Loading branch information
WillStrohl authored Oct 14, 2022
2 parents 5d4c9dc + fa57386 commit 08d0740
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions Libraries/Hotcakes.Commerce/Catalog/ProductRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,33 +521,31 @@ public List<Product> FindMany(IEnumerable<string> productBvins)

public List<Product> FindManyWithCache(IEnumerable<string> productBvins)
{
var result = new List<Product>();
var cachedProducts = new List<Product>();
var needsRetrieval = new List<string>();

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<Product>();
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;
}
Expand Down

0 comments on commit 08d0740

Please sign in to comment.