From c11a324f871c99d033803c9a3b5f27d855af49d4 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 20 Feb 2023 20:27:08 +0100 Subject: [PATCH] Improve deletion performance. --- .../Commands/DomainObject.cs | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/backend/src/Squidex.Infrastructure/Commands/DomainObject.cs b/backend/src/Squidex.Infrastructure/Commands/DomainObject.cs index f0f0bbd38..767a3e6cc 100644 --- a/backend/src/Squidex.Infrastructure/Commands/DomainObject.cs +++ b/backend/src/Squidex.Infrastructure/Commands/DomainObject.cs @@ -178,22 +178,12 @@ public abstract partial class DomainObject : 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.