abp icon indicating copy to clipboard operation
abp copied to clipboard

entity change event

Open henrydingchina opened this issue 2 months ago • 3 comments

Image

Adding over a thousand pieces of data took 30,000 milliseconds?

I don't quite understand the logic here. Is there a setting to turn it off?

public class Assf : UnitOfWork
    {
       
        public Assf(IServiceProvider serviceProvider, IOptions<AbpUnitOfWorkDefaultOptions> options):base(serviceProvider, options)
        {
        }

        #region Overrides of UnitOfWork

        protected override async Task OnCompletedAsync()
        {
            foreach (var handler in CompletedHandlers)
            {
                Stopwatch cw = new Stopwatch();
                cw.Start();
                await handler.Invoke();
                cw.Stop();
                var ss = cw.ElapsedMilliseconds;
                if (ss>30000)
                {
                    
                }
            }
        }

        #endregion
    }

henrydingchina avatar Nov 13 '25 07:11 henrydingchina

abp version:3.3.2

henrydingchina avatar Nov 13 '25 08:11 henrydingchina

hi

You can override the EntityChangeEventHelper to skip some events for your insert operators.

https://github.com/abpframework/abp/blob/a2cbdb41480d1faa018ef5ec3cb34b2cc1084b3d/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangeEventHelper.cs#L22

maliming avatar Nov 14 '25 02:11 maliming

Yes, I have already reviewed the source code for this part. It seems to be collecting a series of events within the work unit. What I am more concerned about is that the methods registered in OnComplete are triggered when the work unit is finished. The event publishing process can be optimized for specific events,

->LocalEventBus : EventBusBase, ILocalEventBus, ISingletonDependency
if (isFirstEvent)
            {
                currentUow.OnCompleted(
                    async () =>
                    {
                        foreach (var eventEntry in eventList)
                        {
                            try
                            {
                                await eventEntry.EventBus.PublishAsync(
                                    eventEntry.EventType,
                                    Activator.CreateInstance(eventEntry.EventType, eventEntry.EntityOrEto)
                                );
                            }
                            catch (Exception ex)
                            {
                                Logger.LogError(
                                    $"Caught an exception while publishing the event '{eventType.FullName}' for the entity '{entityOrEto}'");
                                Logger.LogException(ex);
                            }
                        }
                    }
                );
            }

henrydingchina avatar Nov 14 '25 11:11 henrydingchina