diff --git a/backend/src/Migrations/Migrations/MongoDb/AddAppIdToEventStream.cs b/backend/src/Migrations/Migrations/MongoDb/AddAppIdToEventStream.cs index cdf1c97386..b69662a93e 100644 --- a/backend/src/Migrations/Migrations/MongoDb/AddAppIdToEventStream.cs +++ b/backend/src/Migrations/Migrations/MongoDb/AddAppIdToEventStream.cs @@ -31,7 +31,8 @@ public async Task UpdateAsync( var collectionV1 = database.GetCollection("Events"); var collectionV2 = database.GetCollection("Events2"); - var batchedCommits = collectionV1.Find(FindAll).ToAsyncEnumerable(ct).Buffered(1000, ct).Batch(500, ct); + // Run batch first, because it is cheaper as it has less items. + var batchedCommits = collectionV1.Find(FindAll).ToAsyncEnumerable(ct).Batch(500, ct).Buffered(2, ct); var options = new ParallelOptions { diff --git a/backend/src/Migrations/Migrations/MongoDb/ConvertDocumentIds.cs b/backend/src/Migrations/Migrations/MongoDb/ConvertDocumentIds.cs index a0d284b4ba..35d1aaa30c 100644 --- a/backend/src/Migrations/Migrations/MongoDb/ConvertDocumentIds.cs +++ b/backend/src/Migrations/Migrations/MongoDb/ConvertDocumentIds.cs @@ -87,7 +87,8 @@ private static async Task RebuildAsync(IMongoDatabase database, Action { diff --git a/backend/src/Squidex.Domain.Apps.Entities/Backup/RestoreProcessor.cs b/backend/src/Squidex.Domain.Apps.Entities/Backup/RestoreProcessor.cs index b5f74784f8..aad9452959 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Backup/RestoreProcessor.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Backup/RestoreProcessor.cs @@ -288,6 +288,7 @@ private async Task DownloadAsync(Run run, private async Task ReadEventsAsync(Run run, CancellationToken ct) { + // Run batch first, because it is cheaper as it has less items. var events = HandleEventsAsync(run, ct).Batch(100, ct).Buffered(2, ct); var handled = 0; diff --git a/backend/src/Squidex.Domain.Apps.Entities/Tags/TagService.cs b/backend/src/Squidex.Domain.Apps.Entities/Tags/TagService.cs index d0cedc8f78..933b7c2035 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Tags/TagService.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Tags/TagService.cs @@ -311,7 +311,8 @@ private async Task> GetStateAsync(DomainId id, string group, public async Task ClearAsync( CancellationToken ct = default) { - var batches = persistenceFactory.Snapshots.ReadAllAsync(ct).Buffered(1000).Batch(500, ct); + // Run batch first, because it is cheaper as it has less items. + var batches = persistenceFactory.Snapshots.ReadAllAsync(ct).Batch(500, ct).Buffered(2); await Parallel.ForEachAsync(batches, ct, async (batch, ct) => { diff --git a/backend/src/Squidex.Infrastructure/Commands/Rebuilder.cs b/backend/src/Squidex.Infrastructure/Commands/Rebuilder.cs index 4b52b86b8c..f98f96153c 100644 --- a/backend/src/Squidex.Infrastructure/Commands/Rebuilder.cs +++ b/backend/src/Squidex.Infrastructure/Commands/Rebuilder.cs @@ -96,7 +96,8 @@ private async Task InsertManyAsync(IAsyncEnumerable source, using (localCache.StartContext()) { - var batches = source.Where(handledIds.Add).Buffered(batchSize * 2, ct).Batch(batchSize, ct); + // Run batch first, because it is cheaper. + var batches = source.Where(handledIds.Add).Batch(batchSize, ct).Buffered(2, ct); await Parallel.ForEachAsync(batches, ct, async (batch, ct) => {