abp icon indicating copy to clipboard operation
abp copied to clipboard

Introduce bulk entity events

Open ahmednfwela opened this issue 2 years ago • 4 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

consider this scenario: you have a separate algolia search server, and you want to sync data between your database and the algolia index.

the current solution is to implement ILocalEventHandler<EntityChangedEventData<TEntity>>. this works when only a single entity is getting changed, but not for InsertMany,UpdateMany,DeleteMany since they will introduce the N+1 problem

Describe the solution you'd like

I suggest that new events to get introduced:

  • IBulkEntityChangeEventHelper
      public interface IBulkEntityChangeEventHelper
      {
          void PublishEntityCreatedEvent(IEnumerable<object> entity);
    
          void PublishEntityUpdatedEvent(IEnumerable<object> entity);
    
          void PublishEntityDeletedEvent(IEnumerable<object> entity);
      }
    
  • BulkEntityEventData -> contains a list of entities
  • BulkEntityChangedEventData -> fired when many entities are changed
  • BulkEntityCreatedEventData -> fired when many entities are created
  • BulkEntityUpdatedEventData -> fired when many entities are updated
  • BulkEntityDeletedEventData -> fired when many entities are deleted

and then we can add a configuration for users to override the behavior of InsertMany, UpdateMany,DeleteMany to control whether the old events EntityChangedEventData are fired alongside the new bulk ones or not

Additional context

No response

ahmednfwela avatar Mar 28 '23 05:03 ahmednfwela

I think the BulkEntitySomeEventData is difficult for event handling. When creating a handler, we must determine whether an entity used bulk operations.

gdlcf88 avatar Mar 28 '23 06:03 gdlcf88

I think it's safer to assume all operations are bulk operations than to assume operations are done individually

ahmednfwela avatar Mar 28 '23 06:03 ahmednfwela

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 10 '23 05:06 stale[bot]

Would be great to have something like this - especially when entities have dependencies, processing each event individually lead to problems where the dependency is not available yet (which mean that the order gets important).

If you have Entity A and B with dependencies of A->B and B->A, you cant handle it without having the whole picture aka a single bulk/many event.

puschie286 avatar Aug 21 '25 10:08 puschie286