Skip to content

Commit 6784416

Browse files
bahusoidfredericDelaporte
authored andcommitted
Add logging for QueryBatch similar to Loader.DoQuery
1 parent 72fddfb commit 6784416

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/NHibernate/Async/Multi/QueryBatchItemBase.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public async Task<int> ProcessResultsSetAsync(DbDataReader reader, CancellationT
3434

3535
var dialect = Session.Factory.Dialect;
3636
var hydratedObjects = new List<object>[_queryInfos.Count];
37+
var isDebugLog = Log.IsDebugEnabled();
3738

3839
using (Session.SwitchCacheMode(_cacheMode))
3940
{
@@ -76,8 +77,15 @@ public async Task<int> ProcessResultsSetAsync(DbDataReader reader, CancellationT
7677
var optionalObjectKey = Loader.Loader.GetOptionalObjectKey(queryParameters, Session);
7778
var tmpResults = new List<object>();
7879

79-
for (var count = 0; count < maxRows && await (reader.ReadAsync(cancellationToken)).ConfigureAwait(false); count++)
80+
if (isDebugLog)
81+
Log.Debug("processing result set");
82+
83+
int count;
84+
for (count = 0; count < maxRows && await (reader.ReadAsync(cancellationToken)).ConfigureAwait(false); count++)
8085
{
86+
if (isDebugLog)
87+
Log.Debug("result set row: {0}", count);
88+
8189
rowCount++;
8290

8391
var o =
@@ -101,6 +109,9 @@ public async Task<int> ProcessResultsSetAsync(DbDataReader reader, CancellationT
101109
tmpResults.Add(o);
102110
}
103111

112+
if (isDebugLog)
113+
Log.Debug("done processing result set ({0} rows)", count);
114+
104115
queryInfo.Result = tmpResults;
105116
if (queryInfo.CanPutToCache)
106117
queryInfo.ResultToCache = new List<object>(tmpResults);

src/NHibernate/Multi/QueryBatchItemBase.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ namespace NHibernate.Multi
1616
/// </summary>
1717
public abstract partial class QueryBatchItemBase<TResult> : IQueryBatchItem<TResult>, IQueryBatchItemWithAsyncProcessResults
1818
{
19+
private static readonly INHibernateLogger Log = NHibernateLogger.For(typeof(QueryBatch));
20+
1921
protected ISessionImplementor Session;
2022
private List<EntityKey[]>[] _subselectResultKeys;
2123
private List<QueryInfo> _queryInfos;
@@ -175,6 +177,7 @@ public int ProcessResultsSet(DbDataReader reader)
175177

176178
var dialect = Session.Factory.Dialect;
177179
var hydratedObjects = new List<object>[_queryInfos.Count];
180+
var isDebugLog = Log.IsDebugEnabled();
178181

179182
using (Session.SwitchCacheMode(_cacheMode))
180183
{
@@ -217,8 +220,15 @@ public int ProcessResultsSet(DbDataReader reader)
217220
var optionalObjectKey = Loader.Loader.GetOptionalObjectKey(queryParameters, Session);
218221
var tmpResults = new List<object>();
219222

220-
for (var count = 0; count < maxRows && reader.Read(); count++)
223+
if (isDebugLog)
224+
Log.Debug("processing result set");
225+
226+
int count;
227+
for (count = 0; count < maxRows && reader.Read(); count++)
221228
{
229+
if (isDebugLog)
230+
Log.Debug("result set row: {0}", count);
231+
222232
rowCount++;
223233

224234
var o =
@@ -242,6 +252,9 @@ public int ProcessResultsSet(DbDataReader reader)
242252
tmpResults.Add(o);
243253
}
244254

255+
if (isDebugLog)
256+
Log.Debug("done processing result set ({0} rows)", count);
257+
245258
queryInfo.Result = tmpResults;
246259
if (queryInfo.CanPutToCache)
247260
queryInfo.ResultToCache = new List<object>(tmpResults);

0 commit comments

Comments
 (0)