Skip to content

Commit 530e953

Browse files
committed
Improve BatchingCommandProcessor
less access to members of context
1 parent 332926e commit 530e953

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

Orm/Xtensive.Orm/Orm/Providers/CommandProcessing/BatchingCommandProcessor.cs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,22 @@ public override void ExecuteTasks(CommandProcessorContext context)
5656
{
5757
PutTasksForExecution(context);
5858

59-
while (context.ProcessingTasks.Count >= batchSize) {
59+
var processingTasks = context.ProcessingTasks;
60+
while (processingTasks.Count >= batchSize) {
6061
_ = ExecuteBatch(batchSize, null, context);
6162
}
6263

63-
var allowPartialExecution = context.AllowPartialExecution;
64-
while (context.ProcessingTasks.Count > 0) {
65-
if (allowPartialExecution) {
66-
//re-register task
67-
RegisterTask(context.ProcessingTasks.Dequeue());
68-
}
69-
else {
70-
_ = context.ProcessingTasks.Count > batchSize
64+
if (!context.AllowPartialExecution) {
65+
while (processingTasks.Count > 0) {
66+
_ = processingTasks.Count > batchSize
7167
? ExecuteBatch(batchSize, null, context)
72-
: ExecuteBatch(context.ProcessingTasks.Count, null, context);
68+
: ExecuteBatch(processingTasks.Count, null, context);
69+
}
70+
}
71+
else {
72+
//re-register task
73+
for (int i = 0, count = processingTasks.Count; i < count; i++) {
74+
tasks.Enqueue(processingTasks.Dequeue());
7375
}
7476
}
7577
}
@@ -78,22 +80,23 @@ public override async Task ExecuteTasksAsync(CommandProcessorContext context, Ca
7880
{
7981
PutTasksForExecution(context);
8082

81-
while (context.ProcessingTasks.Count >= batchSize) {
83+
var processingTasks = context.ProcessingTasks;
84+
while (processingTasks.Count >= batchSize) {
8285
_ = await ExecuteBatchAsync(batchSize, null, context, token).ConfigureAwait(false);
8386
}
8487

85-
var allowPartialExecution = context.AllowPartialExecution;
86-
while (context.ProcessingTasks.Count > 0) {
87-
if (allowPartialExecution) {
88-
//re-register task
89-
RegisterTask(context.ProcessingTasks.Dequeue());
90-
}
91-
else {
88+
if (!context.AllowPartialExecution) {
89+
while (processingTasks.Count > 0) {
9290
_ = await ((context.ProcessingTasks.Count > batchSize)
9391
? ExecuteBatchAsync(batchSize, null, context, token)
9492
: ExecuteBatchAsync(context.ProcessingTasks.Count, null, context, token));
9593
}
9694
}
95+
else {
96+
for(int i = 0, count = processingTasks.Count; i < count; i++) {
97+
tasks.Enqueue(processingTasks.Dequeue());
98+
}
99+
}
97100
}
98101

99102
public override IEnumerator<Tuple> ExecuteTasksWithReader(QueryRequest request, CommandProcessorContext context)

0 commit comments

Comments
 (0)