OnTransformingIndexValues
is being called twice during a “Save and Publish” operation, but only once during a regular “Save”. This actually makes sense. However, I would prefer the method to only run during publish, as it performs a heavy operation. Is this possible?
public class MyIndexingHandler(IExamineManager _examineManager, IHeavyTaskService _heavyTaskService) : INotificationHandler<UmbracoApplicationStartingNotification>
{
public void Handle(UmbracoApplicationStartingNotification notification)
{
if (!_examineManager.TryGetIndex(Umbraco.Cms.Core.Constants.UmbracoIndexes.ExternalIndexName, out var index))
throw new InvalidOperationException("ExternalIndex not found");
if (index is not BaseIndexProvider indexProvider)
throw new InvalidOperationException("Index provider cast failed");
indexProvider.TransformingIndexValues += OnTransformingIndexValues;
}
private void OnTransformingIndexValues(object? sender, IndexingItemEventArgs e)
{
// OnTransformingIndexValues is being called twice during a "Save and Publish" operation, but only once during a regular "Save".
// This actually makes sense. However, I would prefer the method to only run during publish, as it performs a heavy operation.
// Is this possible?
var heavyItem = _heavyTaskService.Get();
HandleHeavyTask(heavyItem);
}
}