Quan Mai
Jul 23, 2020
(4 votes)

New ReferenceConverter method in Commerce 13.21

As you might have heard - ReferenceConverter is your friend. It is very lightweight way to map between the ContentReference and code of catalog content, instead of having to load the content - which is both slow and expensive. Whenever you have chance, ReferenceConverter should be used.

But it is now even better. In Commerce 13.21, ReferenceConverter has a new method to get multiple codes at once. It looks like this

public virtual IDictionary<ContentReference, string> GetCodes(IEnumerable<ContentReference> contentLinks, CatalogContentType catalogContentType)

A common scenario for this new method is when you need to get all variants of a product (by using IRelationRepository), then get all prices or inventories for those variants. Instead of

var allVariantCodes = allVariantLinks.Select(x => _referenceConverter.GetCode(x));

You can now call

var allVariantCodes = _referenceConverter.GetCodes(allVariantLinks, CatalogContentType.CatalogEntry).Values;

The former can result in multiple database roundtrips - depending on how many variants you have. The latter always results in at most 1 database roundtrip. As we all know each roundtrip adds overhead, so there will be a performance improvement.

Jul 23, 2020


Stefan Holm Olsen
Stefan Holm Olsen Jul 23, 2020 10:43 AM

This is great news, Quan.

I have been wishing for this for some time.

Aria Zanganeh
Aria Zanganeh Jul 30, 2020 12:31 AM

woohoo .. now my schedule jobs that import catalog can run faster!

Mari Jørgensen
Mari Jørgensen Aug 4, 2020 11:05 AM

Great! Keep em coming! ;)

Stefan Holm Olsen
Stefan Holm Olsen Aug 15, 2020 05:03 PM

@Quan Mai: I have a similar optimization wish for batch loading CMS content without first loading core data.

I once raised this thread related to ContentAreaItem batch loading, which resulted in many roundtrips even when I called IContentLoader.GetItems on the content area items.

Do you know whether the CMS team has something planned for this?

Please login to comment.
Latest blogs
Plug-in manager is back in CMS 12

Plug-in manager is back in the UI, what is it and how can i use it?

Luc Gosso (MVP) | Oct 6, 2022 | Syndicated blog

Display Child Pages in Content Delivery API Response

The below example will implement an instance of IContentConverterProvider to customise the serialisation of PageData and output child pages in the...

Minesh Shah (Netcel) | Oct 4, 2022

Bring the Report Center back in Optimizely CMS 12

The Report Center has been a part of Optimizely CMS since its first debut in version 5R2 in 2008, but in CMS 12, it's removed! Don't despair! Make...

Tomas Hensrud Gulla | Oct 4, 2022 | Syndicated blog

Customizing Property Lists in Optimizely CMS

Generic property lists is a cool editorial feature that has gained a lot of popularity - in spite of still being unsupported (officially). But if y...

Allan Thraen | Oct 2, 2022 | Syndicated blog