SaaS CMS has officially launched! Learn more now.

IContentRepository.GetReferencesToContent issue for CommerceMediaCollection


We are trying to use GetReferencesToContent method of content repository to determine if a media file is referenced by any products/variants. It seems to return content reference to all products that have a reference to the media file, which is fine, but if I remove the reference on all those products, save them with content repository and then call the GetReferencesToContent again, it returns the same references as the first time. The references are in fact removed and they don't show up in the UI.

Is there any caching delay for this method?

Jan 28, 2021 10:56

Are you removing those via code? If that's the case, them the following link may be helpful

Jan 28, 2021 15:29

Hi! I am using the following code to delete so that's not the issue:

var clone = content.CreateWritableClone<EntryContentBase>();
var commerceMedia = clone.CommerceMediaCollection.FirstOrDefault(x => x.AssetLink.CompareToIgnoreWorkID(mediaData.ContentLink));

if (commerceMedia != null)
    _contentRepository.Save(clone, SaveAction.ForceCurrentVersion, AccessLevel.NoAccess);
Jan 28, 2021 15:49

Looks like a bug, when you make changes to the assets, the cache that is used by GetReferencesToContent  is not properly cleared. I will file a bug to Commerce team. Thanks for bringing this into our attention.

Jan 28, 2021 15:57

Thanks Quan!

This is the workaround I'm using until the bug is fixed. 😂

$"SELECT [CatalogEntryId] FROM [CatalogItemAsset] WHERE [CatalogEntryId] > 0 AND [AssetKey] LIKE '%{resourceId}'"

Edited, Jan 28, 2021 16:01

For future visitors: said bug has been fixed in 13.30 :) 

Mar 11, 2021 12:11
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.