Skip to content

Commit

Permalink
feat: improve BatchProcessor.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexyakunin committed Sep 14, 2023
1 parent 3dd7536 commit 5299830
Show file tree
Hide file tree
Showing 5 changed files with 385 additions and 162 deletions.
6 changes: 2 additions & 4 deletions src/Stl.Fusion.EntityFramework/DbEntityResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ protected Func<TDbContext, TKey[], IAsyncEnumerable<TDbEntity>> CreateCompiledQu
var tenant = TenantRegistry.Get(tenantId);
var batchProcessor = new BatchProcessor<TKey, TDbEntity?> {
BatchSize = Settings.BatchSize,
ConcurrencyLevel = 1,
Implementation = (batch, cancellationToken) => ProcessBatch(tenant, batch, cancellationToken),
};
Settings.ConfigureBatchProcessor?.Invoke(batchProcessor);
Expand All @@ -212,7 +211,7 @@ protected Func<TDbContext, TKey[], IAsyncEnumerable<TDbEntity>> CreateCompiledQu

protected virtual async Task ProcessBatch(
Tenant tenant,
List<BatchItem<TKey, TDbEntity?>> batch,
List<BatchProcessor<TKey, TDbEntity?>.Item> batch,
CancellationToken cancellationToken)
{
if (batch.Count == 0)
Expand All @@ -227,8 +226,7 @@ protected virtual async Task ProcessBatch(
try {
var i = 0;
foreach (var item in batch)
if (!item.TryCancel())
keys[i++] = item.Input;
keys[i++] = item.Input;
var lastKey = keys[i - 1];
for (; i < batchSize; i++)
keys[i] = lastKey;
Expand Down
30 changes: 0 additions & 30 deletions src/Stl/Async/BatchItem.cs

This file was deleted.

Loading

0 comments on commit 5299830

Please sign in to comment.