Browse Source

Fix restore.

pull/897/head
Sebastian 4 years ago
parent
commit
aed441783c
  1. 26
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs
  2. 28
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs

26
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs

@ -21,7 +21,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
{ {
public partial class MongoContentRepository : IContentRepository, IInitializable public partial class MongoContentRepository : IContentRepository, IInitializable
{ {
private readonly MongoContentCollection collectionAll; private readonly MongoContentCollection collectionFrontend;
private readonly MongoContentCollection collectionPublished; private readonly MongoContentCollection collectionPublished;
private readonly IAppProvider appProvider; private readonly IAppProvider appProvider;
@ -32,7 +32,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
public MongoContentRepository(IMongoDatabase database, IAppProvider appProvider) public MongoContentRepository(IMongoDatabase database, IAppProvider appProvider)
{ {
collectionAll = collectionFrontend =
new MongoContentCollection("States_Contents_All3", database, appProvider, new MongoContentCollection("States_Contents_All3", database, appProvider,
ReadPreference.Primary); ReadPreference.Primary);
@ -46,20 +46,20 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
public async Task InitializeAsync( public async Task InitializeAsync(
CancellationToken ct) CancellationToken ct)
{ {
await collectionAll.InitializeAsync(ct); await collectionFrontend.InitializeAsync(ct);
await collectionPublished.InitializeAsync(ct); await collectionPublished.InitializeAsync(ct);
} }
public IAsyncEnumerable<IContentEntity> StreamAll(DomainId appId, HashSet<DomainId>? schemaIds, public IAsyncEnumerable<IContentEntity> StreamAll(DomainId appId, HashSet<DomainId>? schemaIds,
CancellationToken ct = default) CancellationToken ct = default)
{ {
return collectionAll.StreamAll(appId, schemaIds, ct); return collectionFrontend.StreamAll(appId, schemaIds, ct);
} }
public IAsyncEnumerable<IContentEntity> QueryScheduledWithoutDataAsync(Instant now, public IAsyncEnumerable<IContentEntity> QueryScheduledWithoutDataAsync(Instant now,
CancellationToken ct = default) CancellationToken ct = default)
{ {
return collectionAll.QueryScheduledWithoutDataAsync(now, ct); return collectionFrontend.QueryScheduledWithoutDataAsync(now, ct);
} }
public Task<IResultList<IContentEntity>> QueryAsync(IAppEntity app, List<ISchemaEntity> schemas, Q q, SearchScope scope, public Task<IResultList<IContentEntity>> QueryAsync(IAppEntity app, List<ISchemaEntity> schemas, Q q, SearchScope scope,
@ -67,7 +67,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
{ {
if (scope == SearchScope.All) if (scope == SearchScope.All)
{ {
return collectionAll.QueryAsync(app, schemas, q, ct); return collectionFrontend.QueryAsync(app, schemas, q, ct);
} }
else else
{ {
@ -80,7 +80,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
{ {
if (scope == SearchScope.All) if (scope == SearchScope.All)
{ {
return collectionAll.QueryAsync(app, schema, q, ct); return collectionFrontend.QueryAsync(app, schema, q, ct);
} }
else else
{ {
@ -93,7 +93,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
{ {
if (scope == SearchScope.All) if (scope == SearchScope.All)
{ {
return collectionAll.FindContentAsync(schema, id, ct); return collectionFrontend.FindContentAsync(schema, id, ct);
} }
else else
{ {
@ -106,7 +106,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
{ {
if (scope == SearchScope.All) if (scope == SearchScope.All)
{ {
return collectionAll.QueryIdsAsync(appId, ids, ct); return collectionFrontend.QueryIdsAsync(appId, ids, ct);
} }
else else
{ {
@ -119,7 +119,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
{ {
if (scope == SearchScope.All) if (scope == SearchScope.All)
{ {
return collectionAll.HasReferrersAsync(appId, contentId, ct); return collectionFrontend.HasReferrersAsync(appId, contentId, ct);
} }
else else
{ {
@ -130,18 +130,18 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
public Task ResetScheduledAsync(DomainId documentId, public Task ResetScheduledAsync(DomainId documentId,
CancellationToken ct = default) CancellationToken ct = default)
{ {
return collectionAll.ResetScheduledAsync(documentId, ct); return collectionFrontend.ResetScheduledAsync(documentId, ct);
} }
public Task<IReadOnlyList<(DomainId SchemaId, DomainId Id, Status Status)>> QueryIdsAsync(DomainId appId, DomainId schemaId, FilterNode<ClrValue> filterNode, public Task<IReadOnlyList<(DomainId SchemaId, DomainId Id, Status Status)>> QueryIdsAsync(DomainId appId, DomainId schemaId, FilterNode<ClrValue> filterNode,
CancellationToken ct = default) CancellationToken ct = default)
{ {
return collectionAll.QueryIdsAsync(appId, schemaId, filterNode, ct); return collectionFrontend.QueryIdsAsync(appId, schemaId, filterNode, ct);
} }
public IEnumerable<IMongoCollection<MongoContentEntity>> GetInternalCollections() public IEnumerable<IMongoCollection<MongoContentEntity>> GetInternalCollections()
{ {
yield return collectionAll.GetInternalCollection(); yield return collectionFrontend.GetInternalCollection();
yield return collectionPublished.GetInternalCollection(); yield return collectionPublished.GetInternalCollection();
} }
} }

28
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs

@ -20,7 +20,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
IAsyncEnumerable<SnapshotResult<ContentDomainObject.State>> ISnapshotStore<ContentDomainObject.State>.ReadAllAsync( IAsyncEnumerable<SnapshotResult<ContentDomainObject.State>> ISnapshotStore<ContentDomainObject.State>.ReadAllAsync(
CancellationToken ct) CancellationToken ct)
{ {
return collectionAll.StreamAll(ct) return collectionFrontend.StreamAll(ct)
.Select(x => new SnapshotResult<ContentDomainObject.State>(x.DocumentId, x.ToState(), x.Version, true)); .Select(x => new SnapshotResult<ContentDomainObject.State>(x.DocumentId, x.ToState(), x.Version, true));
} }
@ -30,7 +30,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
using (Telemetry.Activities.StartActivity("MongoContentRepository/ReadAsync")) using (Telemetry.Activities.StartActivity("MongoContentRepository/ReadAsync"))
{ {
var existing = var existing =
await collectionAll.FindAsync(key, ct); await collectionFrontend.FindAsync(key, ct);
if (existing?.IsSnapshot == true) if (existing?.IsSnapshot == true)
{ {
@ -46,7 +46,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
{ {
using (Telemetry.Activities.StartActivity("MongoContentRepository/DeleteAppAsync")) using (Telemetry.Activities.StartActivity("MongoContentRepository/DeleteAppAsync"))
{ {
await collectionAll.DeleteAppAsync(app.Id, ct); await collectionFrontend.DeleteAppAsync(app.Id, ct);
await collectionPublished.DeleteAppAsync(app.Id, ct); await collectionPublished.DeleteAppAsync(app.Id, ct);
} }
} }
@ -56,7 +56,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
{ {
using (Telemetry.Activities.StartActivity("MongoContentRepository/ClearAsync")) using (Telemetry.Activities.StartActivity("MongoContentRepository/ClearAsync"))
{ {
await collectionAll.ClearAsync(ct); await collectionFrontend.ClearAsync(ct);
await collectionPublished.ClearAsync(ct); await collectionPublished.ClearAsync(ct);
} }
} }
@ -66,7 +66,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
{ {
using (Telemetry.Activities.StartActivity("MongoContentRepository/RemoveAsync")) using (Telemetry.Activities.StartActivity("MongoContentRepository/RemoveAsync"))
{ {
await collectionAll.RemoveAsync(key, ct); await collectionFrontend.RemoveAsync(key, ct);
await collectionPublished.RemoveAsync(key, ct); await collectionPublished.RemoveAsync(key, ct);
} }
} }
@ -82,8 +82,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
} }
await Task.WhenAll( await Task.WhenAll(
UpsertDraftContentAsync(job, ct), UpsertFrontendAsync(job, ct),
UpsertOrDeletePublishedAsync(job, ct)); UpsertPublishedAsync(job, ct));
} }
} }
@ -93,7 +93,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
using (Telemetry.Activities.StartActivity("MongoContentRepository/WriteManyAsync")) using (Telemetry.Activities.StartActivity("MongoContentRepository/WriteManyAsync"))
{ {
var entitiesPublished = new List<MongoContentEntity>(); var entitiesPublished = new List<MongoContentEntity>();
var entitiesAll = new List<MongoContentEntity>(); var entitiesFrontend = new List<MongoContentEntity>();
foreach (var job in jobs.Where(IsValid)) foreach (var job in jobs.Where(IsValid))
{ {
@ -102,16 +102,16 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
entitiesPublished.Add(await MongoContentEntity.CreatePublishedAsync(job, appProvider)); entitiesPublished.Add(await MongoContentEntity.CreatePublishedAsync(job, appProvider));
} }
entitiesAll.Add(await MongoContentEntity.CreateDraftAsync(job, appProvider)); entitiesFrontend.Add(await MongoContentEntity.CreateDraftAsync(job, appProvider));
} }
await Task.WhenAll( await Task.WhenAll(
collectionPublished.InsertManyAsync(entitiesPublished, ct), collectionFrontend.InsertManyAsync(entitiesFrontend, ct),
collectionAll.InsertManyAsync(entitiesAll, ct)); collectionPublished.InsertManyAsync(entitiesPublished, ct));
} }
} }
private async Task UpsertOrDeletePublishedAsync(SnapshotWriteJob<ContentDomainObject.State> job, private async Task UpsertPublishedAsync(SnapshotWriteJob<ContentDomainObject.State> job,
CancellationToken ct = default) CancellationToken ct = default)
{ {
if (ShouldWritePublished(job.Value)) if (ShouldWritePublished(job.Value))
@ -132,12 +132,12 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
return collectionPublished.RemoveAsync(documentId, ct); return collectionPublished.RemoveAsync(documentId, ct);
} }
private async Task UpsertDraftContentAsync(SnapshotWriteJob<ContentDomainObject.State> job, private async Task UpsertFrontendAsync(SnapshotWriteJob<ContentDomainObject.State> job,
CancellationToken ct = default) CancellationToken ct = default)
{ {
var entity = await MongoContentEntity.CreateDraftAsync(job, appProvider); var entity = await MongoContentEntity.CreateDraftAsync(job, appProvider);
await collectionAll.UpsertVersionedAsync(entity.DocumentId, job.OldVersion, entity, ct); await collectionFrontend.UpsertVersionedAsync(entity.DocumentId, job.OldVersion, entity, ct);
} }
private async Task UpsertPublishedContentAsync(SnapshotWriteJob<ContentDomainObject.State> job, private async Task UpsertPublishedContentAsync(SnapshotWriteJob<ContentDomainObject.State> job,

Loading…
Cancel
Save