11
11
using System ;
12
12
using System . Collections ;
13
13
using System . Collections . Generic ;
14
- using System . Linq ;
15
14
using NHibernate . Cfg ;
16
15
using NHibernate . Engine ;
17
16
using NHibernate . Persister . Collection ;
@@ -100,7 +99,7 @@ public async Task<IList> GetAsync(
100
99
return null ;
101
100
}
102
101
103
- var timestamp = ( long ) cacheable [ 0 ] ;
102
+ var timestamp = GetResultsMetadata ( cacheable , out var aliases ) ;
104
103
105
104
if ( Log . IsDebugEnabled ( ) )
106
105
Log . Debug ( "Checking query spaces for up-to-dateness [{0}]" , StringHelper . CollectionToString ( spaces ) ) ;
@@ -115,7 +114,6 @@ public async Task<IList> GetAsync(
115
114
116
115
if ( result != null && key . ResultTransformer ? . AutoDiscoverTypes == true && result . Count > 0 )
117
116
{
118
- var aliases = ( string [ ] ) cacheable [ 1 ] ;
119
117
key . ResultTransformer . SupplyAutoDiscoveredParameters ( queryParameters . ResultTransformer , aliases ) ;
120
118
}
121
119
@@ -142,7 +140,7 @@ public async Task<IList> GetAsync(QueryKey key, ICacheAssembler[] returnTypes, b
142
140
return null ;
143
141
}
144
142
145
- var timestamp = ( long ) cacheable [ 0 ] ;
143
+ var timestamp = GetResultsMetadata ( cacheable , out var _ ) ;
146
144
147
145
if ( Log . IsDebugEnabled ( ) )
148
146
Log . Debug ( "Checking query spaces for up-to-dateness [{0}]" , StringHelper . CollectionToString ( spaces ) ) ;
@@ -221,10 +219,16 @@ public async Task<IList[]> GetManyAsync(
221
219
222
220
spacesToCheck . Add ( querySpaces ) ;
223
221
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 ) ;
226
224
if ( Log . IsDebugEnabled ( ) )
227
225
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
+ }
228
232
}
229
233
230
234
var upToDates = spacesToCheck . Count > 0
@@ -263,12 +267,6 @@ public async Task<IList[]> GetManyAsync(
263
267
264
268
finalReturnTypes [ i ] = GetReturnTypes ( key , returnTypes [ i ] , cacheable ) ;
265
269
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
- }
272
270
}
273
271
274
272
for ( var i = 0 ; i < keys . Length ; i ++ )
@@ -334,7 +332,12 @@ private static async Task<List<object>> GetCacheableResultAsync(
334
332
long ts , string [ ] aliases , CancellationToken cancellationToken )
335
333
{
336
334
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
+
338
341
foreach ( var row in result )
339
342
{
340
343
if ( returnTypes . Length == 1 )
@@ -343,7 +346,7 @@ private static async Task<List<object>> GetCacheableResultAsync(
343
346
}
344
347
else
345
348
{
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 ) ) ;
347
350
}
348
351
}
349
352
0 commit comments