1212using System . Collections ;
1313using System . Collections . Generic ;
1414using System . Diagnostics ;
15+ using System . Linq ;
1516using NHibernate . Cache ;
1617using NHibernate . Driver ;
1718using NHibernate . Engine ;
@@ -56,7 +57,14 @@ public partial class MultiQueryImpl : IMultiQuery
5657 try
5758 {
5859 Before ( ) ;
59- return cacheable ? await ( ListUsingQueryCacheAsync ( cancellationToken ) ) . ConfigureAwait ( false ) : await ( ListIgnoreQueryCacheAsync ( cancellationToken ) ) . ConfigureAwait ( false ) ;
60+
61+ var querySpaces = new HashSet < string > ( Translators . SelectMany ( t => t . QuerySpaces ) ) ;
62+ if ( resultSetsCommand . HasQueries )
63+ {
64+ await ( session . AutoFlushIfRequiredAsync ( querySpaces , cancellationToken ) ) . ConfigureAwait ( false ) ;
65+ }
66+
67+ return cacheable ? await ( ListUsingQueryCacheAsync ( querySpaces , cancellationToken ) ) . ConfigureAwait ( false ) : await ( ListIgnoreQueryCacheAsync ( cancellationToken ) ) . ConfigureAwait ( false ) ;
6068 }
6169 finally
6270 {
@@ -188,27 +196,6 @@ protected async Task<List<object>> DoListAsync(CancellationToken cancellationTok
188196 return results ;
189197 }
190198
191- private async Task AggregateQueriesInformationAsync ( CancellationToken cancellationToken )
192- {
193- cancellationToken . ThrowIfCancellationRequested ( ) ;
194- int queryIndex = 0 ;
195- foreach ( AbstractQueryImpl query in queries )
196- {
197- query . VerifyParameters ( ) ;
198- QueryParameters queryParameters = query . GetQueryParameters ( ) ;
199- queryParameters . ValidateParameters ( ) ;
200- foreach ( var translator in await ( query . GetTranslatorsAsync ( session , queryParameters , cancellationToken ) ) . ConfigureAwait ( false ) )
201- {
202- translators . Add ( translator ) ;
203- translatorQueryMap . Add ( queryIndex ) ;
204- parameters . Add ( queryParameters ) ;
205- ISqlCommand singleCommand = translator . Loader . CreateSqlCommand ( queryParameters , session ) ;
206- resultSetsCommand . Append ( singleCommand ) ;
207- }
208- queryIndex ++ ;
209- }
210- }
211-
212199 public async Task < object > GetResultAsync ( string key , CancellationToken cancellationToken = default ( CancellationToken ) )
213200 {
214201 cancellationToken . ThrowIfCancellationRequested ( ) ;
@@ -232,19 +219,17 @@ private async Task<IList> ListIgnoreQueryCacheAsync(CancellationToken cancellati
232219 return GetResultList ( await ( DoListAsync ( cancellationToken ) ) . ConfigureAwait ( false ) ) ;
233220 }
234221
235- private async Task < IList > ListUsingQueryCacheAsync ( CancellationToken cancellationToken )
222+ private async Task < IList > ListUsingQueryCacheAsync ( HashSet < string > querySpaces , CancellationToken cancellationToken )
236223 {
237224 cancellationToken . ThrowIfCancellationRequested ( ) ;
238225 IQueryCache queryCache = session . Factory . GetQueryCache ( cacheRegion ) ;
239226
240227 ISet < FilterKey > filterKeys = FilterKey . CreateFilterKeys ( session . EnabledFilters ) ;
241228
242- ISet < string > querySpaces = new HashSet < string > ( ) ;
243229 List < IType [ ] > resultTypesList = new List < IType [ ] > ( Translators . Count ) ;
244230 for ( int i = 0 ; i < Translators . Count ; i ++ )
245231 {
246232 ITranslator queryTranslator = Translators [ i ] ;
247- querySpaces . UnionWith ( queryTranslator . QuerySpaces ) ;
248233 resultTypesList . Add ( queryTranslator . ReturnTypes ) ;
249234 }
250235 int [ ] firstRows = new int [ Parameters . Count ] ;
0 commit comments