Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Installer generated by HCC (BUG) #413

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update Method FindManyWithCache
Optimization of the FindManyWithCache method.

 Reduction of multiple traversals via foreach to input parameters. A reduction to only one was made.

The call to the FindMany method was changed by a call to the Find method that already inside it adds the product to the cache storage
arielblancoupendo committed Oct 7, 2022
commit 180400d52b2830c623b59a98e4eb447daaa592e4
26 changes: 11 additions & 15 deletions Libraries/Hotcakes.Commerce/Catalog/ProductRepository.cs
Original file line number Diff line number Diff line change
@@ -519,33 +519,29 @@ 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));

var result = new List<Product>();
foreach (var productBvin in productBvins)
{
{
Find(productBvin);
var lastAddProduct = CacheManager.GetProduct(productBvin, Context.CurrentStore.Id, Context.MainContentCulture);
if (lastAddProduct != null)
{
cachedProducts.Add(lastAddProduct);
}
}
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;
}