Skip to content

Commit

Permalink
WIP on dotnet#20664
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Mar 4, 2022
1 parent 466fe62 commit 6047cfc
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions src/EFCore.Relational/Update/Internal/CommandBatchPreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,12 @@ public CommandBatchPreparer(CommandBatchPreparerDependencies dependencies)
var parameterNameGenerator = Dependencies.ParameterNameGeneratorFactory.Create();
var commands = CreateModificationCommands(entries, updateAdapter, parameterNameGenerator.GenerateNext);
var sortedCommandSets = TopologicalSort(commands);
var batch = Dependencies.ModificationCommandBatchFactory.Create();

for (var commandSetIndex = 0; commandSetIndex < sortedCommandSets.Count; commandSetIndex++)
foreach (var independentCommandSet in sortedCommandSets)
{
var independentCommandSet = sortedCommandSets[commandSetIndex];

independentCommandSet.Sort(Dependencies.ModificationCommandComparer);

var batch = Dependencies.ModificationCommandBatchFactory.Create();
foreach (var modificationCommand in independentCommandSet)
{
(modificationCommand as ModificationCommand)?.AssertColumnsNotInitialized();
Expand Down Expand Up @@ -106,34 +104,32 @@ public CommandBatchPreparer(CommandBatchPreparerDependencies dependencies)
batch = StartNewBatch(parameterNameGenerator, modificationCommand);
}
}
}

var hasMoreCommandSets = commandSetIndex < sortedCommandSets.Count - 1;

if (batch.ModificationCommands.Count == 1
|| batch.ModificationCommands.Count >= _minBatchSize)
if (batch.ModificationCommands.Count == 1
|| batch.ModificationCommands.Count >= _minBatchSize)
{
if (batch.ModificationCommands.Count > 1)
{
if (batch.ModificationCommands.Count > 1)
{
Dependencies.UpdateLogger.BatchReadyForExecution(
batch.ModificationCommands.SelectMany(c => c.Entries), batch.ModificationCommands.Count);
}
Dependencies.UpdateLogger.BatchReadyForExecution(
batch.ModificationCommands.SelectMany(c => c.Entries), batch.ModificationCommands.Count);
}

batch.Complete();
batch.Complete();

yield return (batch, hasMoreCommandSets);
}
else
{
Dependencies.UpdateLogger.BatchSmallerThanMinBatchSize(
batch.ModificationCommands.SelectMany(c => c.Entries), batch.ModificationCommands.Count, _minBatchSize);
yield return (batch, false);
}
else
{
Dependencies.UpdateLogger.BatchSmallerThanMinBatchSize(
batch.ModificationCommands.SelectMany(c => c.Entries), batch.ModificationCommands.Count, _minBatchSize);

for (var commandIndex = 0; commandIndex < batch.ModificationCommands.Count; commandIndex++)
{
var singleCommandBatch = StartNewBatch(parameterNameGenerator, batch.ModificationCommands[commandIndex]);
singleCommandBatch.Complete();
for (var commandIndex = 0; commandIndex < batch.ModificationCommands.Count; commandIndex++)
{
var singleCommandBatch = StartNewBatch(parameterNameGenerator, batch.ModificationCommands[commandIndex]);
singleCommandBatch.Complete();

yield return (singleCommandBatch, hasMoreCommandSets || commandIndex < batch.ModificationCommands.Count - 1);
}
yield return (singleCommandBatch, commandIndex < batch.ModificationCommands.Count - 1);
}
}
}
Expand Down

0 comments on commit 6047cfc

Please sign in to comment.