diff --git a/backend/src/Squidex.Infrastructure/Commands/DomainObject.cs b/backend/src/Squidex.Infrastructure/Commands/DomainObject.cs index eb109b48f..da4beb8d7 100644 --- a/backend/src/Squidex.Infrastructure/Commands/DomainObject.cs +++ b/backend/src/Squidex.Infrastructure/Commands/DomainObject.cs @@ -312,6 +312,11 @@ namespace Squidex.Infrastructure.Commands if (persistence != null) { await persistence.ReadAsync(); + + if (persistence.IsSnapshotStale) + { + await persistence.WriteSnapshotAsync(Snapshot); + } } } diff --git a/backend/src/Squidex.Infrastructure/States/BatchPersistence.cs b/backend/src/Squidex.Infrastructure/States/BatchPersistence.cs index cc2c1e0e8..d599bc56c 100644 --- a/backend/src/Squidex.Infrastructure/States/BatchPersistence.cs +++ b/backend/src/Squidex.Infrastructure/States/BatchPersistence.cs @@ -21,6 +21,8 @@ namespace Squidex.Infrastructure.States public long Version { get; } + public bool IsSnapshotStale => false; + internal BatchPersistence(DomainId ownerKey, BatchContext context, long version, IReadOnlyList> @events, HandleEvent? applyEvent) { diff --git a/backend/src/Squidex.Infrastructure/States/IPersistence.cs b/backend/src/Squidex.Infrastructure/States/IPersistence.cs index c21e7c2f7..8f3a2fe72 100644 --- a/backend/src/Squidex.Infrastructure/States/IPersistence.cs +++ b/backend/src/Squidex.Infrastructure/States/IPersistence.cs @@ -15,6 +15,8 @@ namespace Squidex.Infrastructure.States { long Version { get; } + bool IsSnapshotStale { get; } + Task DeleteAsync(); Task WriteEventsAsync(IReadOnlyList> events); diff --git a/backend/src/Squidex.Infrastructure/States/Persistence.cs b/backend/src/Squidex.Infrastructure/States/Persistence.cs index f87f9eecf..b4a2dbbe9 100644 --- a/backend/src/Squidex.Infrastructure/States/Persistence.cs +++ b/backend/src/Squidex.Infrastructure/States/Persistence.cs @@ -44,6 +44,11 @@ namespace Squidex.Infrastructure.States get => (persistenceMode & PersistenceMode.EventSourcing) == PersistenceMode.EventSourcing; } + public bool IsSnapshotStale + { + get => persistenceMode == PersistenceMode.SnapshotsAndEventSourcing && versionSnapshot < versionEvents; + } + public Persistence(DomainId ownerKey, Type ownerType, ISnapshotStore snapshotStore, IEventStore eventStore,