November Happy Hour will be moved to Thursday December 5th.

IContentRepository.GetReferencesToContent issue for CommerceMediaCollection

Vote:
 

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?

#247818
Jan 28, 2021 10:56
Vote:
 

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

https://support.episerver.com/hc/en-us/articles/115003738211-Deleting-CommerceMedia-leaves-the-asset-row-intact

#247824
Jan 28, 2021 15:29
Vote:
 

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)
{
    clone.CommerceMediaCollection.Remove(commerceMedia);
    _contentRepository.Save(clone, SaveAction.ForceCurrentVersion, AccessLevel.NoAccess);
}
#247825
Jan 28, 2021 15:49
Vote:
 

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.

#247827
Jan 28, 2021 15:57
Vote:
 

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}'"

#247829
Edited, Jan 28, 2021 16:01
Vote:
 

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

#249898
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.