From 8e445622372b025e23d5653d7b2e5cb65e12868b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 23 Mar 2022 14:31:00 +0100 Subject: [PATCH] Fix in backup. --- .../src/Squidex.Domain.Apps.Entities/Apps/BackupApps.cs | 3 ++- .../Apps/Indexes/AppsIndex.cs | 6 ++++++ .../Apps/Indexes/IAppsIndex.cs | 3 +++ .../Backup/IBackupHandler.cs | 2 +- .../Squidex.Domain.Apps.Entities/Backup/RestoreGrain.cs | 2 +- .../Apps/BackupAppsTests.cs | 5 ++++- .../Apps/Indexes/AppsIndexTests.cs | 9 +++++++++ 7 files changed, 26 insertions(+), 4 deletions(-) diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/BackupApps.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/BackupApps.cs index 33cc63b78b..2c4b340037 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/BackupApps.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/BackupApps.cs @@ -135,10 +135,11 @@ public async Task CleanupRestoreErrorAsync(DomainId appId) await appsIndex.RemoveReservationAsync(appReservation); } - public async Task CompleteRestoreAsync(RestoreContext context) + public async Task CompleteRestoreAsync(RestoreContext context, string appName) { await rebuilder.InsertManyAsync(Enumerable.Repeat(context.AppId, 1), 1, default); + await appsIndex.RegisterAsync(context.AppId, appName); await appsIndex.RemoveReservationAsync(appReservation); } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/Indexes/AppsIndex.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/Indexes/AppsIndex.cs index c0a6be9e57..2f7546bd36 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/Indexes/AppsIndex.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/Indexes/AppsIndex.cs @@ -34,6 +34,12 @@ public AppsIndex(IAppRepository appRepository, IGrainFactory grainFactory, IRepl this.grainCache = grainCache; } + public Task RegisterAsync(DomainId id, string name, + CancellationToken ct = default) + { + return Cache().AddAsync(id, name); + } + public Task RemoveReservationAsync(string? token, CancellationToken ct = default) { diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/Indexes/IAppsIndex.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/Indexes/IAppsIndex.cs index 15cb5163bd..73f5d57d4a 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/Indexes/IAppsIndex.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/Indexes/IAppsIndex.cs @@ -24,6 +24,9 @@ Task> GetAppsForUserAsync(string userId, PermissionSet permissi Task ReserveAsync(DomainId id, string name, CancellationToken ct = default); + Task RegisterAsync(DomainId id, string name, + CancellationToken ct = default); + Task RemoveReservationAsync(string? token, CancellationToken ct = default); } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Backup/IBackupHandler.cs b/backend/src/Squidex.Domain.Apps.Entities/Backup/IBackupHandler.cs index 5b428c5ab6..093054ece4 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Backup/IBackupHandler.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Backup/IBackupHandler.cs @@ -43,7 +43,7 @@ public Task CleanupRestoreErrorAsync(DomainId appId) return Task.CompletedTask; } - public Task CompleteRestoreAsync(RestoreContext context) + public Task CompleteRestoreAsync(RestoreContext context, string appName) { return Task.CompletedTask; } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Backup/RestoreGrain.cs b/backend/src/Squidex.Domain.Apps.Entities/Backup/RestoreGrain.cs index 8978d06c20..b4ed14071b 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Backup/RestoreGrain.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Backup/RestoreGrain.cs @@ -168,7 +168,7 @@ private async Task ProcessAsync() { using (Telemetry.Activities.StartActivity($"{handler.GetType().Name}/CompleteRestoreAsync")) { - await handler.CompleteRestoreAsync(runningContext); + await handler.CompleteRestoreAsync(runningContext, CurrentJob.NewAppName!); } Log($"Completed {handler.Name}"); diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/BackupAppsTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/BackupAppsTests.cs index 6cad836879..776c093f7c 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/BackupAppsTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/BackupAppsTests.cs @@ -79,11 +79,14 @@ await sut.RestoreEventAsync(Envelope.Create(new AppCreated Name = appName }), context, ct); - await sut.CompleteRestoreAsync(context); + await sut.CompleteRestoreAsync(context, appName); A.CallTo(() => appsIndex.RemoveReservationAsync("Reservation", default)) .MustHaveHappened(); + A.CallTo(() => appsIndex.RegisterAsync(appId, appName, default)) + .MustHaveHappened(); + A.CallTo(() => rebuilder.InsertManyAsync(A>.That.Is(appId), 1, default)) .MustHaveHappened(); } diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Indexes/AppsIndexTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Indexes/AppsIndexTests.cs index db5df2433d..c8cc562df3 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Indexes/AppsIndexTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Indexes/AppsIndexTests.cs @@ -320,6 +320,15 @@ public async Task Should_forward_remove_reservation() .MustHaveHappened(); } + [Fact] + public async Task Should_forward_registation() + { + await sut.RegisterAsync(appId.Id, appId.Name); + + A.CallTo(() => cache.AddAsync(appId.Id, appId.Name)) + .MustHaveHappened(); + } + private (IAppEntity, IAppGrain) CreateApp(long version = 0, bool fromClient = false, bool isArchived = false) { var app = A.Fake();