Skip to content

Commit ae9c660

Browse files
Apply code suggestions
Co-authored-by: Alex Zaytsev <[email protected]>
1 parent 4b1d56b commit ae9c660

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

src/NHibernate/Async/Cache/StandardQueryCache.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,9 @@ public async Task<IList[]> GetManyAsync(
214214
continue;
215215
}
216216

217-
var timestamp = GetResultsMetadata(cacheable, out var aliases); var key = keys[i];
218-
if (key.ResultTransformer?.AutoDiscoverTypes == true && HasResults(cacheable))
217+
var timestamp = GetResultsMetadata(cacheable, out var aliases);
218+
var key = keys[i];
219+
if (key.ResultTransformer?.AutoDiscoverTypes == true && !IsEmpty(cacheable))
219220
{
220221
key.ResultTransformer.SupplyAutoDiscoveredParameters(queryParameters[i].ResultTransformer, aliases);
221222
}
@@ -330,7 +331,8 @@ private static async Task<List<object>> GetCacheableResultAsync(
330331
ICacheAssembler[] returnTypes,
331332
ISessionImplementor session,
332333
IList result,
333-
long ts, string[] aliases, CancellationToken cancellationToken)
334+
long ts,
335+
string[] aliases, CancellationToken cancellationToken)
334336
{
335337
cancellationToken.ThrowIfCancellationRequested();
336338
var cacheable =
@@ -360,7 +362,7 @@ private static async Task PerformBeforeAssembleAsync(
360362
IList cacheable, CancellationToken cancellationToken)
361363
{
362364
cancellationToken.ThrowIfCancellationRequested();
363-
if (!HasResults(cacheable))
365+
if (IsEmpty(cacheable))
364366
return;
365367

366368
if (returnTypes.Length == 1)
@@ -392,7 +394,7 @@ private async Task<IList> PerformAssembleAsync(
392394
try
393395
{
394396
var result = new List<object>(cacheable.Count - 1);
395-
if (!HasResults(cacheable))
397+
if (IsEmpty(cacheable))
396398
return result;
397399

398400
if (returnTypes.Length == 1)
@@ -449,7 +451,7 @@ private static async Task InitializeCollectionsAsync(
449451
IList cacheResult, CancellationToken cancellationToken)
450452
{
451453
cancellationToken.ThrowIfCancellationRequested();
452-
if (!HasResults(cacheResult))
454+
if (IsEmpty(cacheResult))
453455
return;
454456

455457
var collectionIndexes = new Dictionary<int, ICollectionPersister>();
@@ -491,7 +493,7 @@ private async Task<IList> GetResultFromCacheableAsync(
491493
cancellationToken.ThrowIfCancellationRequested();
492494
Log.Debug("returning cached query results for: {0}", key);
493495

494-
if (!HasResults(cacheable))
496+
if (IsEmpty(cacheable))
495497
return new List<object>();
496498

497499
returnTypes = GetReturnTypes(key, returnTypes, cacheable);

src/NHibernate/Cache/StandardQueryCache.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,9 @@ public IList[] GetMany(
249249
continue;
250250
}
251251

252-
var timestamp = GetResultsMetadata(cacheable, out var aliases); var key = keys[i];
253-
if (key.ResultTransformer?.AutoDiscoverTypes == true && HasResults(cacheable))
252+
var timestamp = GetResultsMetadata(cacheable, out var aliases);
253+
var key = keys[i];
254+
if (key.ResultTransformer?.AutoDiscoverTypes == true && !IsEmpty(cacheable))
254255
{
255256
key.ResultTransformer.SupplyAutoDiscoveredParameters(queryParameters[i].ResultTransformer, aliases);
256257
}
@@ -371,7 +372,8 @@ private static List<object> GetCacheableResult(
371372
ICacheAssembler[] returnTypes,
372373
ISessionImplementor session,
373374
IList result,
374-
long ts, string[] aliases)
375+
long ts,
376+
string[] aliases)
375377
{
376378
var cacheable =
377379
new List<object>(result.Count + 1)
@@ -407,9 +409,9 @@ private static long GetResultsMetadata(IList cacheable, out string[] aliases)
407409
return (long) metadataArray[0];
408410
}
409411

410-
private static bool HasResults(IList cacheable)
412+
private static bool IsEmpty(IList cacheable)
411413
// First element is the timestamp.
412-
=> cacheable.Count > 1;
414+
=> cacheable.Count <= 1;
413415

414416
private static IEnumerable<object> GetResultsEnumerable(IList cacheable)
415417
{
@@ -425,7 +427,7 @@ private static ICacheAssembler[] GetReturnTypes(
425427
ICacheAssembler[] returnTypes,
426428
IList cacheable)
427429
{
428-
var hasResults = HasResults(cacheable);
430+
var hasResults = !IsEmpty(cacheable);
429431
if (key.ResultTransformer?.AutoDiscoverTypes == true && hasResults)
430432
{
431433
returnTypes = GuessTypes(cacheable);
@@ -444,7 +446,7 @@ private static void PerformBeforeAssemble(
444446
ISessionImplementor session,
445447
IList cacheable)
446448
{
447-
if (!HasResults(cacheable))
449+
if (IsEmpty(cacheable))
448450
return;
449451

450452
if (returnTypes.Length == 1)
@@ -475,7 +477,7 @@ private IList PerformAssemble(
475477
try
476478
{
477479
var result = new List<object>(cacheable.Count - 1);
478-
if (!HasResults(cacheable))
480+
if (IsEmpty(cacheable))
479481
return result;
480482

481483
if (returnTypes.Length == 1)
@@ -531,7 +533,7 @@ private static void InitializeCollections(
531533
IList assembleResult,
532534
IList cacheResult)
533535
{
534-
if (!HasResults(cacheResult))
536+
if (IsEmpty(cacheResult))
535537
return;
536538

537539
var collectionIndexes = new Dictionary<int, ICollectionPersister>();
@@ -572,7 +574,7 @@ private IList GetResultFromCacheable(
572574
{
573575
Log.Debug("returning cached query results for: {0}", key);
574576

575-
if (!HasResults(cacheable))
577+
if (IsEmpty(cacheable))
576578
return new List<object>();
577579

578580
returnTypes = GetReturnTypes(key, returnTypes, cacheable);

0 commit comments

Comments
 (0)