Epinova / Epinova.Elasticsearch

A search-plugin for Episerver CMS and Commerce
MIT License
29 stars 20 forks source link

Media deleted during indexing causes indexer scheduled job to fail #155

Closed jonatanjii closed 2 years ago

jonatanjii commented 2 years ago

https://github.com/Epinova/Epinova.Elasticsearch/blob/975972ea78ccf2a69578881035c006e68697dbe1/src/Epinova.ElasticSearch.Core.EPiServer/Indexer.cs#L313

This throws an exception if media doesn´t exist anymore (has been deleted after the indexing job was started) and it causes the entire indexing job to fail. Exception handling is needed to make sure the job continues indexing remaining media.

IContent owner = _contentAssetHelper.GetAssetOwner(content.ContentLink);

private bool IsFormUpload(IContent content)
{
    IContent owner = _contentAssetHelper.GetAssetOwner(content.ContentLink);

    if(owner == null)
    {
        return false;
    }

    return owner.GetType().GetInterfaces()
        .Select(i => i.FullName)
        .Contains(FormsUploadNamespace);
}
otanum commented 2 years ago

Hi @jonatanjii

Could you please verify? Fixed in 11.7.4.228? Added null check for content in SkipIndexing method. SkipIndexing is the only method calling IsFormUpload.

jonatanjii commented 2 years ago

@otanum hi, a null check wont be enough since the variable content wont be null (already loaded into memory). It´s the call to "_contentAssetHelper.GetAssetOwner(content.ContentLink)" that is throwing a not found exception.

GetAssetOwner wont return null if content is not found, it will throw a not found exception so you need a try catch around this method call.

otanum commented 2 years ago

@jonatanjii https://github.com/Epinova/Epinova.Elasticsearch/commit/75f831f7d7ce5236efa2dd4d68a5bc648f270633

otanum commented 2 years ago

11.7.4.230

jonatanjii commented 2 years ago

@otanum looks good!