|
|
@ -7,10 +7,12 @@ |
|
|
|
|
|
|
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.Linq; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
using Squidex.Domain.Apps.Entities.Backup; |
|
|
using Squidex.Domain.Apps.Entities.Backup; |
|
|
using Squidex.Domain.Apps.Entities.Contents.State; |
|
|
using Squidex.Domain.Apps.Entities.Contents.State; |
|
|
using Squidex.Domain.Apps.Events.Contents; |
|
|
using Squidex.Domain.Apps.Events.Contents; |
|
|
|
|
|
using Squidex.Domain.Apps.Events.Schemas; |
|
|
using Squidex.Infrastructure; |
|
|
using Squidex.Infrastructure; |
|
|
using Squidex.Infrastructure.EventSourcing; |
|
|
using Squidex.Infrastructure.EventSourcing; |
|
|
using Squidex.Infrastructure.States; |
|
|
using Squidex.Infrastructure.States; |
|
|
@ -20,7 +22,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
{ |
|
|
{ |
|
|
public sealed class BackupContents : BackupHandlerWithStore |
|
|
public sealed class BackupContents : BackupHandlerWithStore |
|
|
{ |
|
|
{ |
|
|
private readonly HashSet<Guid> contentIds = new HashSet<Guid>(); |
|
|
private readonly Dictionary<Guid, HashSet<Guid>> contentIdsBySchemaId = new Dictionary<Guid, HashSet<Guid>>(); |
|
|
|
|
|
|
|
|
public override string Name { get; } = "Contents"; |
|
|
public override string Name { get; } = "Contents"; |
|
|
|
|
|
|
|
|
@ -34,7 +36,10 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
switch (@event.Payload) |
|
|
switch (@event.Payload) |
|
|
{ |
|
|
{ |
|
|
case ContentCreated contentCreated: |
|
|
case ContentCreated contentCreated: |
|
|
contentIds.Add(contentCreated.ContentId); |
|
|
contentIdsBySchemaId.GetOrAddNew(contentCreated.SchemaId.Id).Add(contentCreated.ContentId); |
|
|
|
|
|
break; |
|
|
|
|
|
case SchemaDeleted schemaDeleted: |
|
|
|
|
|
contentIdsBySchemaId.Remove(schemaDeleted.SchemaId.Id); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -43,6 +48,8 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
|
|
|
|
|
public override Task RestoreAsync(Guid appId, BackupReader reader) |
|
|
public override Task RestoreAsync(Guid appId, BackupReader reader) |
|
|
{ |
|
|
{ |
|
|
|
|
|
var contentIds = contentIdsBySchemaId.Values.SelectMany(x => x); |
|
|
|
|
|
|
|
|
return RebuildManyAsync(contentIds, id => RebuildAsync<ContentState, ContentGrain>(id, (e, s) => s.Apply(e))); |
|
|
return RebuildManyAsync(contentIds, id => RebuildAsync<ContentState, ContentGrain>(id, (e, s) => s.Apply(e))); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|