November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
I moved this discussion to Commerce forum.
First of all this can be much faster if you use indexed search, instead of content APIs.
Second of all you are trying to load content multiple times. Try something like this (pseudo code)
var booksList = _contentLoader.GetDescendents(categoryContentLink)
.Select(p => GetBookProduct(p))
.Where(p => p != null)
.OrderBy(p => p.PublishedDate)
.Take(24);
private BookProduct GetBookProduct(ContentReference contentLink)
{
BookProduct bookProduct;
_contentLoader.TryGet<BookProduct>(contentLink, Helper.GetCultureInfo(CountryCode), out bookProduct);
return bookProduct;
}
not sure why the final foreach is needed.
Final of all, are you expecting the category to have subcategories? Otherwise GetChildren should be enough.
Hi,
Thanks for your reply, I m afraid that didn't speed up things, I guess since I have more than 2K items inside a category it gets stuck in converting them into BookProduct object.
I end up running a loop for each sub-cat and adding Books into a list and then OrderBY and pick top 24, didnt seems to be processor intensive and was very quick.
To answer you question I have further sub-cat thats why I used GetDescendents().
var booksList = _contentLoader.GetChildren<BookProduct>(categoryContentLink).ToList(); var bookListNode = _contentLoader.GetChildren<ProductListingNode>(categoryContentLink); foreach (var node in bookListNode) { booksList.AddRange(_contentLoader.GetChildren<BookProduct>(categoryContentLink).ToList()); } booksList = booksList.OrderBy(p => p.PublishedDate).Take(24).ToList();
Thanks for you help, as always your reply saved the day.
Thanks,
Anurag
Hi,
I am trying to get top 24 products in a category based on "PublishedDate" property. So far I got this :
var booksList = _contentLoader.GetDescendents(categoryContentLink)(p, Helper.GetCultureInfo(CountryCode)) is BookProduct)(p, Helper.GetCultureInfo(CountryCode)))
.Where(p => _contentLoader.Get
.Select(p => _contentLoader.Get
.OrderBy(p => p.PublishedDate)
.Take(24);
foreach(var book in booksList)(book.ContentLink, "en-GB");
{
var product = _contentLoader.Get
}
If remove OrderBy clause then everything works but with OrderBy clause system hangs on foreach loop and doesnt excute further.
Please suggest if I am doing anything wrong.
Thanks,
Anurag