Skip to content

Commit 130a23b

Browse files
committed
Fix tests
1 parent 407fbe8 commit 130a23b

1 file changed

Lines changed: 21 additions & 15 deletions

File tree

Orm/Xtensive.Orm/Orm/Providers/SqlSessionHandler.IProviderExecutor.cs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,29 +85,35 @@ private void Execute(ParameterContext parameterContext)
8585

8686
private void Store(IPersistDescriptor descriptor, IEnumerable<Tuple> tuples)
8787
{
88-
if (descriptor.LazyLevel1BatchStoreRequest != null && descriptor.LazyLevel2BatchStoreRequest != null) {
89-
foreach (var level2Chunk in tuples.Chunk(WellKnown.MultiRowInsertLevel2BatchSize)) {
90-
if (level2Chunk.Length == WellKnown.MultiRowInsertLevel2BatchSize) {
88+
using var enumerator = tuples.GetEnumerator();
89+
if (!enumerator.MoveNext()) {
90+
return;
91+
}
92+
var firstTuple = enumerator.Current;
93+
if (firstTuple.Count == 1 && descriptor.LazyLevel1BatchStoreRequest != null && descriptor.LazyLevel2BatchStoreRequest != null) {
94+
var level2Chunk = new List<Tuple>(WellKnown.MultiRowInsertLevel2BatchSize) { firstTuple };
95+
while (enumerator.MoveNext()) {
96+
level2Chunk.Add(enumerator.Current);
97+
if (level2Chunk.Count == WellKnown.MultiRowInsertLevel2BatchSize) {
9198
commandProcessor.RegisterTask(new SqlPersistTask(descriptor.LazyLevel2BatchStoreRequest.Value, level2Chunk));
99+
level2Chunk = new(WellKnown.MultiRowInsertLevel2BatchSize);
100+
}
101+
}
102+
foreach (var level1Chunk in level2Chunk.Chunk(WellKnown.MultiRowInsertLevel1BatchSize)) {
103+
if (level1Chunk.Length == WellKnown.MultiRowInsertLevel1BatchSize) {
104+
commandProcessor.RegisterTask(new SqlPersistTask(descriptor.LazyLevel1BatchStoreRequest.Value, level1Chunk));
92105
}
93106
else {
94-
foreach (var level1Chunk in level2Chunk.Chunk(WellKnown.MultiRowInsertLevel1BatchSize)) {
95-
if (level1Chunk.Length == WellKnown.MultiRowInsertLevel1BatchSize) {
96-
commandProcessor.RegisterTask(new SqlPersistTask(descriptor.LazyLevel1BatchStoreRequest.Value, level1Chunk));
97-
}
98-
else {
99-
foreach (var tuple in level1Chunk) {
100-
commandProcessor.RegisterTask(new SqlPersistTask(descriptor.LazyStoreRequest.Value, tuple));
101-
}
102-
}
107+
foreach (var tuple in level1Chunk) {
108+
commandProcessor.RegisterTask(new SqlPersistTask(descriptor.LazyStoreRequest.Value, tuple));
103109
}
104110
}
105111
}
106112
}
107113
else {
108-
foreach (var tuple in tuples) {
109-
commandProcessor.RegisterTask(new SqlPersistTask(descriptor.LazyStoreRequest.Value, tuple));
110-
}
114+
do {
115+
commandProcessor.RegisterTask(new SqlPersistTask(descriptor.LazyStoreRequest.Value, enumerator.Current));
116+
} while (enumerator.MoveNext());
111117
}
112118
}
113119
}

0 commit comments

Comments
 (0)