Skip to content

Commit 41fad6b

Browse files
Improve the fix
1 parent d2d49b5 commit 41fad6b

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

src/NHibernate/Async/Engine/BatchFetchQueue.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ async Task<bool> CheckCacheAndProcessResultAsync()
102102
? collectionKeys.Count - Math.Min(batchSize, collectionKeys.Count)
103103
: 0;
104104
var toIndex = collectionKeys.Count - 1;
105-
// In case the collection having triggered the load was not registered for batching, load
106-
// most recently registered collections.
107-
var indexes = GetSortedKeyIndexes(collectionKeys, keyIndex ?? -1, fromIndex, toIndex);
105+
var indexes = GetSortedKeyIndexes(collectionKeys, keyIndex, fromIndex, toIndex);
108106
if (batchableCache == null)
109107
{
110108
for (var j = 0; j < collectionKeys.Count; j++)
@@ -297,10 +295,7 @@ async Task<bool> CheckCacheAndProcessResultAsync()
297295
? entityKeys.Count - Math.Min(batchSize, entityKeys.Count)
298296
: 0;
299297
var toIndex = entityKeys.Count - 1;
300-
// In case of an ISession.Get on an entity not already loaded as an uninitialized proxy,
301-
// it will not be found in entities awaiting a load, and idIndex will be null. Providing
302-
// -1 then allows to take the entities most recently loaded as uninitialized proxies.
303-
var indexes = GetSortedKeyIndexes(entityKeys, idIndex ?? -1, fromIndex, toIndex);
298+
var indexes = GetSortedKeyIndexes(entityKeys, idIndex, fromIndex, toIndex);
304299
if (batchableCache == null)
305300
{
306301
for (var j = 0; j < entityKeys.Count; j++)

src/NHibernate/Engine/BatchFetchQueue.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,7 @@ bool CheckCacheAndProcessResult()
271271
? collectionKeys.Count - Math.Min(batchSize, collectionKeys.Count)
272272
: 0;
273273
var toIndex = collectionKeys.Count - 1;
274-
// In case the collection having triggered the load was not registered for batching, load
275-
// most recently registered collections.
276-
var indexes = GetSortedKeyIndexes(collectionKeys, keyIndex ?? -1, fromIndex, toIndex);
274+
var indexes = GetSortedKeyIndexes(collectionKeys, keyIndex, fromIndex, toIndex);
277275
if (batchableCache == null)
278276
{
279277
for (var j = 0; j < collectionKeys.Count; j++)
@@ -457,10 +455,7 @@ bool CheckCacheAndProcessResult()
457455
? entityKeys.Count - Math.Min(batchSize, entityKeys.Count)
458456
: 0;
459457
var toIndex = entityKeys.Count - 1;
460-
// In case of an ISession.Get on an entity not already loaded as an uninitialized proxy,
461-
// it will not be found in entities awaiting a load, and idIndex will be null. Providing
462-
// -1 then allows to take the entities most recently loaded as uninitialized proxies.
463-
var indexes = GetSortedKeyIndexes(entityKeys, idIndex ?? -1, fromIndex, toIndex);
458+
var indexes = GetSortedKeyIndexes(entityKeys, idIndex, fromIndex, toIndex);
464459
if (batchableCache == null)
465460
{
466461
for (var j = 0; j < entityKeys.Count; j++)
@@ -626,13 +621,15 @@ private bool[] AreCached(List<KeyValuePair<KeyValuePair<CollectionEntry, IPersis
626621
/// <param name="fromIndex">The index where the sorting will begin.</param>
627622
/// <param name="toIndex">The index where the sorting will end.</param>
628623
/// <returns>An array of sorted key indexes.</returns>
629-
private static int[] GetSortedKeyIndexes<T>(List<KeyValuePair<T, int>> keys, int keyIndex, int fromIndex, int toIndex)
624+
private static int[] GetSortedKeyIndexes<T>(List<KeyValuePair<T, int>> keys, int? keyIndex, int fromIndex, int toIndex)
630625
{
631626
var result = new int[Math.Abs(toIndex - fromIndex) + 1];
632627
var lowerIndexes = new List<int>();
633628
var i = 0;
634629
for (var j = fromIndex; j <= toIndex; j++)
635630
{
631+
// If the index was not found (null), this test will be falsy and it will take the most recently
632+
// registered entities or collections.
636633
if (keys[j].Value < keyIndex)
637634
{
638635
lowerIndexes.Add(j);

0 commit comments

Comments
 (0)