OnTransformingIndexValues is being called twice during a "Save and Publish" operation

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);
	}
}

Has anyone found a solution for only triggering indexing on publish using indexProvider.TransformingIndexValues ?

My goal is to add custom data to the External Index when a page is published and I am using code similar to the OP. I do notice the save-problem is only happening when the page has been previously published.