Skip to content

Commit

Permalink
SagaRepository now checks if there are events and command to publish …
Browse files Browse the repository at this point in the history
…before calling the method as a minor optimisation.
  • Loading branch information
cdmdotnet committed Oct 17, 2024
1 parent 68c0238 commit 6048287
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions Framework/Cqrs/Domain/SagaRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,25 @@ async Task SaveAsync
IEnumerable<IEvent<TAuthenticationToken>> nonSagaEventsToPublish = saga.GetUnpublishedNonSagaEvents();
if (!uncommittedChanges.Any())
{
if (commandsToPublish.Any())
{
#if NET40
PublishCommands
PublishCommands
#else
await PublishCommandsAsync
await PublishCommandsAsync
#endif
(commandsToPublish);
(commandsToPublish);
}

if (nonSagaEventsToPublish.Any())
{
#if NET40
PublishEvents
PublishEvents
#else
await PublishEventsAsync
await PublishEventsAsync
#endif
(nonSagaEventsToPublish);
(nonSagaEventsToPublish);
}
return;
}

Expand Down Expand Up @@ -175,19 +181,25 @@ await PublishEventAsync
(@event);
}

if (commandsToPublish.Any())
{
#if NET40
PublishCommands
PublishCommands
#else
await PublishCommandsAsync
await PublishCommandsAsync
#endif
(commandsToPublish);
(commandsToPublish);
}

if (nonSagaEventsToPublish.Any())
{
#if NET40
PublishEvents
PublishEvents
#else
await PublishEventsAsync
await PublishEventsAsync
#endif
(nonSagaEventsToPublish);
(nonSagaEventsToPublish);
}
}

/// <summary>
Expand Down

0 comments on commit 6048287

Please sign in to comment.