CustomHierarchicalCatalogPartialRouter performance

Vote:
 

Hi,

I am using product code in url but my code not startdard it include some special characters. So i have to normalize it and then add to url

from normalize code in url i can't denomalize to actual code to get product by ContentRepository so i have to query to episerver FIND to get product

The issue is that, time to query to find to get product too long lead to performance impact

    //incoming
        protected override CatalogContentBase FindNextContentInSegmentPair(CatalogContentBase catalogContent, SegmentPair segmentPair, SegmentContext segmentContext, CultureInfo cultureInfo)
        {
            while (!string.IsNullOrWhiteSpace(segmentPair.Next) && segmentContext.RequestUrl.IsAbsoluteUri &&
                   segmentContext.RequestUrl.AbsolutePath.Contains("/product/"))
            {
                if (catalogContent.ContentType == CatalogContentType.Root)
                {
                    var code = $"{Constants.ARTICLE_PREFIX}_{segmentPair.Next}";
                    // Performance issue here
                    var singleProduct = _queryService.FindProductByNormalizeCode(code, _currentMarket.GetCurrentMarket().MarketId.Value);

                    if (product != nul)
                    {
                        if (contentLoader.TryGet(contentLink, out ProductContent product))
                        {
                            return product;
                        }

                        return singleProduct;
                    }
                }
                segmentContext.RemainingPath = string.Empty;
                segmentPair = segmentContext.GetNextValue(segmentPair.Remaining);
            }

            return base.FindNextContentInSegmentPair(catalogContent, segmentPair, segmentContext, cultureInfo);
        }

So my question:

Is there any way to get product by nomalize code from episerver

Thanks,

Thang Le

#231095
Nov 19, 2020 7:12
Vote:
 

You can certainly add a cache to that, can be as simple as a Dictionary<string, ContentReference>(). 

There is no "normalized" code support in Episerver.

And I think you might be referring to UrlSegment (aka name in url), not code. 

#231112
Nov 19, 2020 8:58
Vote:
 

Hi Quan,

Can i use ProjectionsSearch to get ProductContent type?

I try use projection but i get exception messeage: Please use GetContentResult extension method for getting results with content types

When i try use GetcontentResult i can't get value of properties set as Ignore attribute

For example:

[Ignore]
public IEnumerable<PriceRange> Prices
{
get; set;
}
[Ignore]
public IEnumerable<ProductAvailability> ProductAvailabilities { get; set; }

Thanks,

Thang Le

#231114
Edited, Nov 19, 2020 10:24
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.