Browse Source

Improve deletion performance.

pull/978/head
Sebastian 4 years ago
parent
commit
c11a324f87
  1. 20
      backend/src/Squidex.Infrastructure/Commands/DomainObject.cs

20
backend/src/Squidex.Infrastructure/Commands/DomainObject.cs

@ -178,22 +178,12 @@ public abstract partial class DomainObject<T> : IAggregate where T : class, IDom
if (uncomittedEvents.Count > 0)
{
var deletedId = DomainId.Combine(UniqueId, DomainId.Create("deleted"));
var deletedStream = persistenceFactory.WithEventSourcing(GetType(), deletedId, null);
// Use the persisistence with snapshots, because it writes to event store without version check.
var deletedName = DomainId.Combine(UniqueId, DomainId.Create("deleted"));
var deletedStream = persistenceFactory.WithSnapshots(GetType(), deletedName, null);
try
{
// Write to the deleted stream first so we never loose this information.
await deletedStream.WriteEventsAsync(uncomittedEvents, ct);
}
catch (InconsistentStateException)
{
// There is another deletion event, therefore we have to fetch the version.
await deletedStream.ReadAsync(ct: default);
await deletedStream.WriteEventsAsync(uncomittedEvents, ct);
}
// Write to the deleted stream first so we never loose this information.
await deletedStream.WriteEventsAsync(uncomittedEvents, ct);
}
// Cleanup the primary stream second.

Loading…
Cancel
Save