From ec02459cc498aebcc786d668b345345ae18fa19a Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 4 May 2019 15:23:40 +0200 Subject: [PATCH] Restore fixes. --- .../Actions/Algolia/AlgoliaAction.cs | 2 +- .../ElasticSearch/ElasticSearchAction.cs | 2 +- .../Apps/BackupApps.cs | 4 +- .../Backup/BackupGrain.cs | 54 +++++++++++++------ .../Backup/BackupHandler.cs | 2 +- .../Backup/Helpers/Downloader.cs | 4 +- .../Backup/Helpers/Safe.cs | 14 ++--- .../Backup/IBackupArchiveLocation.cs | 5 +- .../Backup/RestoreGrain.cs | 46 +++++++++------- .../Backup/TempFolderBackupArchiveLocation.cs | 7 ++- .../pages/backups/backups-page.component.html | 2 +- src/Squidex/appsettings.json | 6 ++- src/Squidex/package-lock.json | 10 ++-- tools/Migrate_00/Program.cs | 2 +- tools/Migrate_01/RebuildOptions.cs | 2 + tools/Migrate_01/RebuildRunner.cs | 11 +++- 16 files changed, 110 insertions(+), 63 deletions(-) diff --git a/extensions/Squidex.Extensions/Actions/Algolia/AlgoliaAction.cs b/extensions/Squidex.Extensions/Actions/Algolia/AlgoliaAction.cs index eb6c041a4..99436019c 100644 --- a/extensions/Squidex.Extensions/Actions/Algolia/AlgoliaAction.cs +++ b/extensions/Squidex.Extensions/Actions/Algolia/AlgoliaAction.cs @@ -15,7 +15,7 @@ namespace Squidex.Extensions.Actions.Algolia IconImage = "", IconColor = "#0d9bf9", Display = "Populate Algolia index", - Description = "Populate and synchronize indices in Algolia for full text search.", + Description = "Populate and synchronize indexes in Algolia for full text search.", ReadMore = "https://www.algolia.com/")] public sealed class AlgoliaAction : RuleAction { diff --git a/extensions/Squidex.Extensions/Actions/ElasticSearch/ElasticSearchAction.cs b/extensions/Squidex.Extensions/Actions/ElasticSearch/ElasticSearchAction.cs index 826f86f6d..67cf4e7d5 100644 --- a/extensions/Squidex.Extensions/Actions/ElasticSearch/ElasticSearchAction.cs +++ b/extensions/Squidex.Extensions/Actions/ElasticSearch/ElasticSearchAction.cs @@ -17,7 +17,7 @@ namespace Squidex.Extensions.Actions.ElasticSearch IconImage = "", IconColor = "#1e5470", Display = "Populate ElasticSearch index", - Description = "Populate and synchronize indices in ElasticSearch for full text search.", + Description = "Populate and synchronize indexes in ElasticSearch for full text search.", ReadMore = "https://www.elastic.co/")] public sealed class ElasticSearchAction : RuleAction { diff --git a/src/Squidex.Domain.Apps.Entities/Apps/BackupApps.cs b/src/Squidex.Domain.Apps.Entities/Apps/BackupApps.cs index 04c99856d..d6f389ecc 100644 --- a/src/Squidex.Domain.Apps.Entities/Apps/BackupApps.cs +++ b/src/Squidex.Domain.Apps.Entities/Apps/BackupApps.cs @@ -127,11 +127,11 @@ namespace Squidex.Domain.Apps.Entities.Apps { if (!(isReserved = await appsByNameIndex.ReserveAppAsync(appId, appName))) { - throw new BackupRestoreException("vThe app id or name is not available."); + throw new BackupRestoreException("The app id or name is not available."); } } - public override async Task CleanupRestoreAsync(Guid appId) + public override async Task CleanupRestoreErrorAsync(Guid appId) { if (isReserved) { diff --git a/src/Squidex.Domain.Apps.Entities/Backup/BackupGrain.cs b/src/Squidex.Domain.Apps.Entities/Backup/BackupGrain.cs index fe6a484ec..4c892946d 100644 --- a/src/Squidex.Domain.Apps.Entities/Backup/BackupGrain.cs +++ b/src/Squidex.Domain.Apps.Entities/Backup/BackupGrain.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using NodaTime; using Orleans.Concurrency; using Squidex.Domain.Apps.Entities.Backup.Helpers; @@ -34,8 +35,8 @@ namespace Squidex.Domain.Apps.Entities.Backup private readonly IAssetStore assetStore; private readonly IBackupArchiveLocation backupArchiveLocation; private readonly IClock clock; - private readonly IEnumerable handlers; private readonly IJsonSerializer serializer; + private readonly IServiceProvider serviceProvider; private readonly IEventDataFormatter eventDataFormatter; private readonly IEventStore eventStore; private readonly ISemanticLog log; @@ -48,8 +49,8 @@ namespace Squidex.Domain.Apps.Entities.Backup IClock clock, IEventStore eventStore, IEventDataFormatter eventDataFormatter, - IEnumerable handlers, IJsonSerializer serializer, + IServiceProvider serviceProvider, ISemanticLog log, IStore store) : base(store) @@ -59,7 +60,7 @@ namespace Squidex.Domain.Apps.Entities.Backup Guard.NotNull(clock, nameof(clock)); Guard.NotNull(eventStore, nameof(eventStore)); Guard.NotNull(eventDataFormatter, nameof(eventDataFormatter)); - Guard.NotNull(handlers, nameof(handlers)); + Guard.NotNull(serviceProvider, nameof(serviceProvider)); Guard.NotNull(serializer, nameof(serializer)); Guard.NotNull(log, nameof(log)); @@ -68,8 +69,8 @@ namespace Squidex.Domain.Apps.Entities.Backup this.clock = clock; this.eventStore = eventStore; this.eventDataFormatter = eventDataFormatter; - this.handlers = handlers; this.serializer = serializer; + this.serviceProvider = serviceProvider; this.log = log; } @@ -86,10 +87,12 @@ namespace Squidex.Domain.Apps.Entities.Backup { if (!job.Stopped.HasValue) { + var jobId = job.Id.ToString(); + job.Stopped = clock.GetCurrentInstant(); - await Safe.DeleteAsync(backupArchiveLocation, job.Id, log); - await Safe.DeleteAsync(assetStore, job.Id, log); + await Safe.DeleteAsync(backupArchiveLocation, jobId, log); + await Safe.DeleteAsync(assetStore, jobId, log); job.Status = JobStatus.Failed; @@ -120,15 +123,29 @@ namespace Squidex.Domain.Apps.Entities.Backup currentTask = new CancellationTokenSource(); currentJob = job; - var lastTimestamp = job.Started; - State.Jobs.Insert(0, job); await WriteStateAsync(); + Process(job, currentTask.Token); + } + + private void Process(BackupStateJob job, CancellationToken ct) + { + ProcessAsync(job, ct).Forget(); + } + + private async Task ProcessAsync(BackupStateJob job, CancellationToken ct) + { + var jobId = job.Id.ToString(); + + var handlers = CreateHandlers(); + + var lastTimestamp = job.Started; + try { - using (var stream = await backupArchiveLocation.OpenStreamAsync(job.Id)) + using (var stream = await backupArchiveLocation.OpenStreamAsync(jobId)) { using (var writer = new BackupWriter(serializer, stream, true)) { @@ -162,16 +179,16 @@ namespace Squidex.Domain.Apps.Entities.Backup stream.Position = 0; - currentTask.Token.ThrowIfCancellationRequested(); + ct.ThrowIfCancellationRequested(); - await assetStore.UploadAsync(job.Id.ToString(), 0, null, stream, false, currentTask.Token); + await assetStore.UploadAsync(jobId, 0, null, stream, false, currentTask.Token); } job.Status = JobStatus.Completed; } catch (Exception ex) { - log.LogError(ex, job.Id.ToString(), (ctx, w) => w + log.LogError(ex, jobId, (ctx, w) => w .WriteProperty("action", "makeBackup") .WriteProperty("status", "failed") .WriteProperty("backupId", ctx)); @@ -180,7 +197,7 @@ namespace Squidex.Domain.Apps.Entities.Backup } finally { - await Safe.DeleteAsync(backupArchiveLocation, job.Id, log); + await Safe.DeleteAsync(backupArchiveLocation, jobId, log); job.Stopped = clock.GetCurrentInstant(); @@ -220,8 +237,10 @@ namespace Squidex.Domain.Apps.Entities.Backup } else { - await Safe.DeleteAsync(backupArchiveLocation, job.Id, log); - await Safe.DeleteAsync(assetStore, job.Id, log); + var jobId = job.Id.ToString(); + + await Safe.DeleteAsync(backupArchiveLocation, jobId, log); + await Safe.DeleteAsync(assetStore, jobId, log); State.Jobs.Remove(job); @@ -229,6 +248,11 @@ namespace Squidex.Domain.Apps.Entities.Backup } } + private IEnumerable CreateHandlers() + { + return serviceProvider.GetRequiredService>(); + } + public Task>> GetStateAsync() { return J.AsTask(State.Jobs.OfType().ToList()); diff --git a/src/Squidex.Domain.Apps.Entities/Backup/BackupHandler.cs b/src/Squidex.Domain.Apps.Entities/Backup/BackupHandler.cs index b891d58d9..dc0bb7b0d 100644 --- a/src/Squidex.Domain.Apps.Entities/Backup/BackupHandler.cs +++ b/src/Squidex.Domain.Apps.Entities/Backup/BackupHandler.cs @@ -37,7 +37,7 @@ namespace Squidex.Domain.Apps.Entities.Backup return TaskHelper.Done; } - public virtual Task CleanupRestoreAsync(Guid appId) + public virtual Task CleanupRestoreErrorAsync(Guid appId) { return TaskHelper.Done; } diff --git a/src/Squidex.Domain.Apps.Entities/Backup/Helpers/Downloader.cs b/src/Squidex.Domain.Apps.Entities/Backup/Helpers/Downloader.cs index 9529c4bf5..5a8aaff9f 100644 --- a/src/Squidex.Domain.Apps.Entities/Backup/Helpers/Downloader.cs +++ b/src/Squidex.Domain.Apps.Entities/Backup/Helpers/Downloader.cs @@ -15,7 +15,7 @@ namespace Squidex.Domain.Apps.Entities.Backup.Helpers { public static class Downloader { - public static async Task DownloadAsync(this IBackupArchiveLocation backupArchiveLocation, Uri url, Guid id) + public static async Task DownloadAsync(this IBackupArchiveLocation backupArchiveLocation, Uri url, string id) { if (string.Equals(url.Scheme, "file")) { @@ -60,7 +60,7 @@ namespace Squidex.Domain.Apps.Entities.Backup.Helpers } } - public static async Task OpenArchiveAsync(this IBackupArchiveLocation backupArchiveLocation, Guid id, IJsonSerializer serializer) + public static async Task OpenArchiveAsync(this IBackupArchiveLocation backupArchiveLocation, string id, IJsonSerializer serializer) { Stream stream = null; diff --git a/src/Squidex.Domain.Apps.Entities/Backup/Helpers/Safe.cs b/src/Squidex.Domain.Apps.Entities/Backup/Helpers/Safe.cs index 9019ce27b..4938b7788 100644 --- a/src/Squidex.Domain.Apps.Entities/Backup/Helpers/Safe.cs +++ b/src/Squidex.Domain.Apps.Entities/Backup/Helpers/Safe.cs @@ -14,7 +14,7 @@ namespace Squidex.Domain.Apps.Entities.Backup.Helpers { public static class Safe { - public static async Task DeleteAsync(IBackupArchiveLocation backupArchiveLocation, Guid id, ISemanticLog log) + public static async Task DeleteAsync(IBackupArchiveLocation backupArchiveLocation, string id, ISemanticLog log) { try { @@ -22,33 +22,33 @@ namespace Squidex.Domain.Apps.Entities.Backup.Helpers } catch (Exception ex) { - log.LogError(ex, id.ToString(), (logOperationId, w) => w + log.LogError(ex, id, (logOperationId, w) => w .WriteProperty("action", "deleteArchive") .WriteProperty("status", "failed") .WriteProperty("operationId", logOperationId)); } } - public static async Task DeleteAsync(IAssetStore assetStore, Guid id, ISemanticLog log) + public static async Task DeleteAsync(IAssetStore assetStore, string id, ISemanticLog log) { try { - await assetStore.DeleteAsync(id.ToString(), 0, null); + await assetStore.DeleteAsync(id, 0, null); } catch (Exception ex) { - log.LogError(ex, id.ToString(), (logOperationId, w) => w + log.LogError(ex, id, (logOperationId, w) => w .WriteProperty("action", "deleteBackup") .WriteProperty("status", "failed") .WriteProperty("operationId", logOperationId)); } } - public static async Task CleanupRestoreAsync(BackupHandler handler, Guid appId, Guid id, ISemanticLog log) + public static async Task CleanupRestoreErrorAsync(BackupHandler handler, Guid appId, Guid id, ISemanticLog log) { try { - await handler.CleanupRestoreAsync(appId); + await handler.CleanupRestoreErrorAsync(appId); } catch (Exception ex) { diff --git a/src/Squidex.Domain.Apps.Entities/Backup/IBackupArchiveLocation.cs b/src/Squidex.Domain.Apps.Entities/Backup/IBackupArchiveLocation.cs index 298372a9c..96c498639 100644 --- a/src/Squidex.Domain.Apps.Entities/Backup/IBackupArchiveLocation.cs +++ b/src/Squidex.Domain.Apps.Entities/Backup/IBackupArchiveLocation.cs @@ -5,7 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using System.IO; using System.Threading.Tasks; @@ -13,8 +12,8 @@ namespace Squidex.Domain.Apps.Entities.Backup { public interface IBackupArchiveLocation { - Task OpenStreamAsync(Guid backupId); + Task OpenStreamAsync(string backupId); - Task DeleteArchiveAsync(Guid backupId); + Task DeleteArchiveAsync(string backupId); } } diff --git a/src/Squidex.Domain.Apps.Entities/Backup/RestoreGrain.cs b/src/Squidex.Domain.Apps.Entities/Backup/RestoreGrain.cs index 9ceec5592..d2cf81238 100644 --- a/src/Squidex.Domain.Apps.Entities/Backup/RestoreGrain.cs +++ b/src/Squidex.Domain.Apps.Entities/Backup/RestoreGrain.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using NodaTime; using Squidex.Domain.Apps.Core.Apps; using Squidex.Domain.Apps.Entities.Apps.Commands; @@ -31,11 +32,11 @@ namespace Squidex.Domain.Apps.Entities.Backup private readonly IBackupArchiveLocation backupArchiveLocation; private readonly IClock clock; private readonly ICommandBus commandBus; - private readonly IEnumerable handlers; private readonly IJsonSerializer serializer; private readonly IEventStore eventStore; private readonly IEventDataFormatter eventDataFormatter; private readonly ISemanticLog log; + private readonly IServiceProvider serviceProvider; private readonly IStreamNameResolver streamNameResolver; private RestoreStateJob CurrentJob @@ -48,9 +49,9 @@ namespace Squidex.Domain.Apps.Entities.Backup ICommandBus commandBus, IEventStore eventStore, IEventDataFormatter eventDataFormatter, - IEnumerable handlers, IJsonSerializer serializer, ISemanticLog log, + IServiceProvider serviceProvider, IStreamNameResolver streamNameResolver, IStore store) : base(store) @@ -60,8 +61,8 @@ namespace Squidex.Domain.Apps.Entities.Backup Guard.NotNull(commandBus, nameof(commandBus)); Guard.NotNull(eventStore, nameof(eventStore)); Guard.NotNull(eventDataFormatter, nameof(eventDataFormatter)); - Guard.NotNull(handlers, nameof(handlers)); Guard.NotNull(serializer, nameof(serializer)); + Guard.NotNull(serviceProvider, nameof(serviceProvider)); Guard.NotNull(store, nameof(store)); Guard.NotNull(streamNameResolver, nameof(streamNameResolver)); Guard.NotNull(log, nameof(log)); @@ -71,8 +72,8 @@ namespace Squidex.Domain.Apps.Entities.Backup this.commandBus = commandBus; this.eventStore = eventStore; this.eventDataFormatter = eventDataFormatter; - this.handlers = handlers; this.serializer = serializer; + this.serviceProvider = serviceProvider; this.streamNameResolver = streamNameResolver; this.log = log; } @@ -88,16 +89,18 @@ namespace Squidex.Domain.Apps.Entities.Backup { if (CurrentJob?.Status == JobStatus.Started) { + var handlers = CreateHandlers(); + Log("Failed due application restart"); CurrentJob.Status = JobStatus.Failed; - await CleanupAsync(); + await CleanupAsync(handlers); await WriteStateAsync(); } } - public Task RestoreAsync(Uri url, RefToken actor, string newAppName) + public async Task RestoreAsync(Uri url, RefToken actor, string newAppName) { Guard.NotNull(url, nameof(url)); Guard.NotNull(actor, nameof(actor)); @@ -122,9 +125,9 @@ namespace Squidex.Domain.Apps.Entities.Backup Url = url }; - Process(); + await WriteStateAsync(); - return TaskHelper.Done; + Process(); } private void Process() @@ -134,6 +137,8 @@ namespace Squidex.Domain.Apps.Entities.Backup private async Task ProcessAsync() { + var handlers = CreateHandlers(); + var logContext = (jobId: CurrentJob.Id.ToString(), jobUrl: CurrentJob.Url.ToString()); using (Profiler.StartSession()) @@ -157,11 +162,11 @@ namespace Squidex.Domain.Apps.Entities.Backup await DownloadAsync(); } - using (var reader = await backupArchiveLocation.OpenArchiveAsync(CurrentJob.Id, serializer)) + using (var reader = await backupArchiveLocation.OpenArchiveAsync(CurrentJob.Id.ToString(), serializer)) { using (Profiler.Trace("ReadEvents")) { - await ReadEventsAsync(reader); + await ReadEventsAsync(reader, handlers); } foreach (var handler in handlers) @@ -212,7 +217,7 @@ namespace Squidex.Domain.Apps.Entities.Backup Log("Failed with internal error"); } - await CleanupAsync(); + await CleanupAsync(handlers); CurrentJob.Status = JobStatus.Failed; @@ -258,15 +263,15 @@ namespace Squidex.Domain.Apps.Entities.Backup } } - private async Task CleanupAsync() + private async Task CleanupAsync(IEnumerable handlers) { - await Safe.DeleteAsync(backupArchiveLocation, CurrentJob.Id, log); + await Safe.DeleteAsync(backupArchiveLocation, CurrentJob.Id.ToString(), log); if (CurrentJob.AppId != Guid.Empty) { foreach (var handler in handlers) { - await Safe.CleanupRestoreAsync(handler, CurrentJob.AppId, CurrentJob.Id, log); + await Safe.CleanupRestoreErrorAsync(handler, CurrentJob.AppId, CurrentJob.Id, log); } } } @@ -275,22 +280,22 @@ namespace Squidex.Domain.Apps.Entities.Backup { Log("Downloading Backup"); - await backupArchiveLocation.DownloadAsync(CurrentJob.Url, CurrentJob.Id); + await backupArchiveLocation.DownloadAsync(CurrentJob.Url, CurrentJob.Id.ToString()); Log("Downloaded Backup"); } - private async Task ReadEventsAsync(BackupReader reader) + private async Task ReadEventsAsync(BackupReader reader, IEnumerable handlers) { await reader.ReadEventsAsync(streamNameResolver, eventDataFormatter, async storedEvent => { - await HandleEventAsync(reader, storedEvent.Stream, storedEvent.Event); + await HandleEventAsync(reader, handlers, storedEvent.Stream, storedEvent.Event); }); Log($"Reading {reader.ReadEvents} events and {reader.ReadAttachments} attachments completed.", true); } - private async Task HandleEventAsync(BackupReader reader, string stream, Envelope @event) + private async Task HandleEventAsync(BackupReader reader, IEnumerable handlers, string stream, Envelope @event) { if (@event.Payload is SquidexEvent squidexEvent) { @@ -340,6 +345,11 @@ namespace Squidex.Domain.Apps.Entities.Backup } } + private IEnumerable CreateHandlers() + { + return serviceProvider.GetRequiredService>(); + } + public Task> GetJobAsync() { return Task.FromResult>(CurrentJob); diff --git a/src/Squidex.Domain.Apps.Entities/Backup/TempFolderBackupArchiveLocation.cs b/src/Squidex.Domain.Apps.Entities/Backup/TempFolderBackupArchiveLocation.cs index 699ec524a..4f5822ce7 100644 --- a/src/Squidex.Domain.Apps.Entities/Backup/TempFolderBackupArchiveLocation.cs +++ b/src/Squidex.Domain.Apps.Entities/Backup/TempFolderBackupArchiveLocation.cs @@ -5,7 +5,6 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using System; using System.IO; using System.Threading.Tasks; using Squidex.Infrastructure.Tasks; @@ -14,14 +13,14 @@ namespace Squidex.Domain.Apps.Entities.Backup { public sealed class TempFolderBackupArchiveLocation : IBackupArchiveLocation { - public Task OpenStreamAsync(Guid backupId) + public Task OpenStreamAsync(string backupId) { var tempFile = GetTempFile(backupId); return Task.FromResult(new FileStream(tempFile, FileMode.OpenOrCreate, FileAccess.ReadWrite)); } - public Task DeleteArchiveAsync(Guid backupId) + public Task DeleteArchiveAsync(string backupId) { var tempFile = GetTempFile(backupId); @@ -36,7 +35,7 @@ namespace Squidex.Domain.Apps.Entities.Backup return TaskHelper.Done; } - private static string GetTempFile(Guid backupId) + private static string GetTempFile(string backupId) { return Path.Combine(Path.GetTempPath(), backupId + ".zip"); } diff --git a/src/Squidex/app/features/settings/pages/backups/backups-page.component.html b/src/Squidex/app/features/settings/pages/backups/backups-page.component.html index 53d3871db..dddcf8cf6 100644 --- a/src/Squidex/app/features/settings/pages/backups/backups-page.component.html +++ b/src/Squidex/app/features/settings/pages/backups/backups-page.component.html @@ -40,7 +40,7 @@
-
+
diff --git a/src/Squidex/appsettings.json b/src/Squidex/appsettings.json index 802116cc0..21bfb1ac0 100644 --- a/src/Squidex/appsettings.json +++ b/src/Squidex/appsettings.json @@ -430,6 +430,10 @@ /* * Set to true to rebuild schemas. */ - "schemas": false + "schemas": false, + /* + * Set to true to rebuild indexes. + */ + "indexes": false } } diff --git a/src/Squidex/package-lock.json b/src/Squidex/package-lock.json index addc1d0f2..70a1d3fa3 100644 --- a/src/Squidex/package-lock.json +++ b/src/Squidex/package-lock.json @@ -2037,7 +2037,7 @@ "dependencies": { "jsesc": { "version": "1.3.0", - "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-1.3.0.tgz", + "resolved": "http://registry.npmjs.org/jsesc/-/jsesc-1.3.0.tgz", "integrity": "sha1-RsP+yMGJKxKwgz25vHYiF226s0s=", "dev": true }, @@ -9249,7 +9249,7 @@ }, "node-fetch": { "version": "2.1.2", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.1.2.tgz", + "resolved": "http://registry.npmjs.org/node-fetch/-/node-fetch-2.1.2.tgz", "integrity": "sha1-q4hOjn5X44qUR1POxwb3iNF2i7U=" }, "node-forge": { @@ -9639,7 +9639,7 @@ }, "onetime": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz", + "resolved": "http://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz", "integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=", "dev": true }, @@ -13298,7 +13298,7 @@ "dependencies": { "json5": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", + "resolved": "http://registry.npmjs.org/json5/-/json5-1.0.1.tgz", "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", "dev": true, "requires": { @@ -15408,7 +15408,7 @@ }, "whatwg-fetch": { "version": "2.0.4", - "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz", + "resolved": "http://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz", "integrity": "sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng==" }, "which": { diff --git a/tools/Migrate_00/Program.cs b/tools/Migrate_00/Program.cs index a4b7f51a4..fd6e59b31 100644 --- a/tools/Migrate_00/Program.cs +++ b/tools/Migrate_00/Program.cs @@ -22,7 +22,7 @@ namespace Migrate_00 var collection = mongoDatabase.GetCollection("Events"); - Console.Write("Migrate Indices....."); + Console.Write("Migrate indexes....."); collection.Indexes.DropAll(); diff --git a/tools/Migrate_01/RebuildOptions.cs b/tools/Migrate_01/RebuildOptions.cs index 436841883..94f9743c9 100644 --- a/tools/Migrate_01/RebuildOptions.cs +++ b/tools/Migrate_01/RebuildOptions.cs @@ -15,6 +15,8 @@ namespace Migrate_01 public bool Contents { get; set; } + public bool Indexes { get; set; } + public bool Rules { get; set; } public bool Schemas { get; set; } diff --git a/tools/Migrate_01/RebuildRunner.cs b/tools/Migrate_01/RebuildRunner.cs index 742e9e670..c14120d5a 100644 --- a/tools/Migrate_01/RebuildRunner.cs +++ b/tools/Migrate_01/RebuildRunner.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Options; +using Migrate_01.Migrations; using Squidex.Infrastructure; namespace Migrate_01 @@ -15,15 +16,18 @@ namespace Migrate_01 public sealed class RebuildRunner { private readonly Rebuilder rebuilder; + private readonly PopulateGrainIndexes populateGrainIndexes; private readonly RebuildOptions rebuildOptions; - public RebuildRunner(Rebuilder rebuilder, IOptions rebuildOptions) + public RebuildRunner(Rebuilder rebuilder, IOptions rebuildOptions, PopulateGrainIndexes populateGrainIndexes) { Guard.NotNull(rebuilder, nameof(rebuilder)); Guard.NotNull(rebuildOptions, nameof(rebuildOptions)); + Guard.NotNull(populateGrainIndexes, nameof(populateGrainIndexes)); this.rebuilder = rebuilder; this.rebuildOptions = rebuildOptions.Value; + this.populateGrainIndexes = populateGrainIndexes; } public async Task RunAsync(CancellationToken ct) @@ -52,6 +56,11 @@ namespace Migrate_01 { await rebuilder.RebuildContentAsync(ct); } + + if (rebuildOptions.Indexes) + { + await populateGrainIndexes.UpdateAsync(); + } } } }