Skip to content

Commit fda5a75

Browse files
Generate async files
1 parent ec0c5a0 commit fda5a75

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/NHibernate.Test/Async/QueryTest/MultiCriteriaFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public async Task CanGetMultiQueryFromSecondLevelCacheAsync()
154154
var cacheHashtable = MultipleQueriesFixtureAsync.GetHashTableUsedAsQueryCache(Sfi);
155155
var cachedListEntry = (IList)new ArrayList(cacheHashtable.Values)[0];
156156
// The first element is a timestamp, then only we have the cached data.
157-
var cachedQuery = (IList) cachedListEntry[1] ?? throw new InvalidOperationException("Cached data is null");
157+
var cachedQuery = (IList)cachedListEntry[1] ?? throw new InvalidOperationException("Cached data is null");
158158

159159
var firstQueryResults = (IList)cachedQuery[0];
160160
firstQueryResults.Clear();

src/NHibernate/Async/Cache/StandardQueryCache.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using System;
1212
using System.Collections;
1313
using System.Collections.Generic;
14-
using System.Linq;
1514
using NHibernate.Cfg;
1615
using NHibernate.Engine;
1716
using NHibernate.Persister.Collection;
@@ -100,7 +99,7 @@ public async Task<IList> GetAsync(
10099
return null;
101100
}
102101

103-
var timestamp = (long) cacheable[0];
102+
var timestamp = GetResultsMetadata(cacheable, out var aliases);
104103

105104
if (Log.IsDebugEnabled())
106105
Log.Debug("Checking query spaces for up-to-dateness [{0}]", StringHelper.CollectionToString(spaces));
@@ -115,7 +114,6 @@ public async Task<IList> GetAsync(
115114

116115
if (result != null && key.ResultTransformer?.AutoDiscoverTypes == true && result.Count > 0)
117116
{
118-
var aliases = (string[]) cacheable[1];
119117
key.ResultTransformer.SupplyAutoDiscoveredParameters(queryParameters.ResultTransformer, aliases);
120118
}
121119

@@ -142,7 +140,7 @@ public async Task<IList> GetAsync(QueryKey key, ICacheAssembler[] returnTypes, b
142140
return null;
143141
}
144142

145-
var timestamp = (long) cacheable[0];
143+
var timestamp = GetResultsMetadata(cacheable, out var _);
146144

147145
if (Log.IsDebugEnabled())
148146
Log.Debug("Checking query spaces for up-to-dateness [{0}]", StringHelper.CollectionToString(spaces));
@@ -221,10 +219,16 @@ public async Task<IList[]> GetManyAsync(
221219

222220
spacesToCheck.Add(querySpaces);
223221
checkedSpacesIndexes.Add(i);
224-
// The timestamp is the first element of the cache result.
225-
checkedSpacesTimestamp.Add((long) cacheable[0]);
222+
var timestamp = GetResultsMetadata(cacheable, out var aliases);
223+
checkedSpacesTimestamp.Add(timestamp);
226224
if (Log.IsDebugEnabled())
227225
Log.Debug("Checking query spaces for up-to-dateness [{0}]", StringHelper.CollectionToString(querySpaces));
226+
227+
var key = keys[i];
228+
if (key.ResultTransformer?.AutoDiscoverTypes == true && HasResults(cacheable))
229+
{
230+
key.ResultTransformer.SupplyAutoDiscoveredParameters(queryParameters[i].ResultTransformer, aliases);
231+
}
228232
}
229233

230234
var upToDates = spacesToCheck.Count > 0
@@ -263,12 +267,6 @@ public async Task<IList[]> GetManyAsync(
263267

264268
finalReturnTypes[i] = GetReturnTypes(key, returnTypes[i], cacheable);
265269
await (PerformBeforeAssembleAsync(finalReturnTypes[i], session, cacheable, cancellationToken)).ConfigureAwait(false);
266-
267-
if (key.ResultTransformer?.AutoDiscoverTypes == true && cacheable.Count > 2)
268-
{
269-
var aliases = (string[]) cacheable[1];
270-
key.ResultTransformer.SupplyAutoDiscoveredParameters(queryParams.ResultTransformer, aliases);
271-
}
272270
}
273271

274272
for (var i = 0; i < keys.Length; i++)
@@ -334,7 +332,12 @@ private static async Task<List<object>> GetCacheableResultAsync(
334332
long ts, string[] aliases, CancellationToken cancellationToken)
335333
{
336334
cancellationToken.ThrowIfCancellationRequested();
337-
var cacheable = new List<object>(result.Count + 2) { ts, aliases };
335+
var cacheable =
336+
new List<object>(result.Count + 1)
337+
{
338+
aliases == null ? ts : new object[] { ts, aliases }
339+
};
340+
338341
foreach (var row in result)
339342
{
340343
if (returnTypes.Length == 1)
@@ -343,7 +346,7 @@ private static async Task<List<object>> GetCacheableResultAsync(
343346
}
344347
else
345348
{
346-
cacheable.Add(await (TypeHelper.DisassembleAsync((object[])row, returnTypes, null, session, null, cancellationToken)).ConfigureAwait(false));
349+
cacheable.Add(await (TypeHelper.DisassembleAsync((object[]) row, returnTypes, null, session, null, cancellationToken)).ConfigureAwait(false));
347350
}
348351
}
349352

0 commit comments

Comments
 (0)