Skip to content

Commit

Permalink
Improve assets.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Jul 22, 2023
1 parent 51ea9d0 commit 00878c8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public async Task UpdateAsync(
var collectionV1 = database.GetCollection<BsonDocument>("Events");
var collectionV2 = database.GetCollection<BsonDocument>("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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ private static async Task RebuildAsync(IMongoDatabase database, Action<BsonDocum

await collectionV2.DeleteManyAsync(FindAll, ct);

var batches = collectionV1.Find(FindAll).ToAsyncEnumerable(ct).Buffered(1000, ct).Batch(500, ct);
// Run batch first, because it is cheaper as it has less items.
var batches = collectionV1.Find(FindAll).ToAsyncEnumerable(ct).Batch(500, ct).Buffered(2, ct);

await Parallel.ForEachAsync(batches, ct, async (batch, ct) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ private async Task<IBackupReader> 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;
Expand Down
3 changes: 2 additions & 1 deletion backend/src/Squidex.Domain.Apps.Entities/Tags/TagService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ private async Task<SimpleState<State>> 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) =>
{
Expand Down
3 changes: 2 additions & 1 deletion backend/src/Squidex.Infrastructure/Commands/Rebuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ private async Task InsertManyAsync<T, TState>(IAsyncEnumerable<DomainId> 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) =>
{
Expand Down

0 comments on commit 00878c8

Please sign in to comment.