Skip to content

Commit

Permalink
Add logging for QueryBatch similar to Loader.DoQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
bahusoid authored and fredericDelaporte committed Jan 14, 2020
1 parent 72fddfb commit 6784416
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/NHibernate/Async/Multi/QueryBatchItemBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public async Task<int> ProcessResultsSetAsync(DbDataReader reader, CancellationT

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

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

for (var count = 0; count < maxRows && await (reader.ReadAsync(cancellationToken)).ConfigureAwait(false); count++)
if (isDebugLog)
Log.Debug("processing result set");

int count;
for (count = 0; count < maxRows && await (reader.ReadAsync(cancellationToken)).ConfigureAwait(false); count++)
{
if (isDebugLog)
Log.Debug("result set row: {0}", count);

rowCount++;

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

if (isDebugLog)
Log.Debug("done processing result set ({0} rows)", count);

queryInfo.Result = tmpResults;
if (queryInfo.CanPutToCache)
queryInfo.ResultToCache = new List<object>(tmpResults);
Expand Down
15 changes: 14 additions & 1 deletion src/NHibernate/Multi/QueryBatchItemBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace NHibernate.Multi
/// </summary>
public abstract partial class QueryBatchItemBase<TResult> : IQueryBatchItem<TResult>, IQueryBatchItemWithAsyncProcessResults
{
private static readonly INHibernateLogger Log = NHibernateLogger.For(typeof(QueryBatch));

protected ISessionImplementor Session;
private List<EntityKey[]>[] _subselectResultKeys;
private List<QueryInfo> _queryInfos;
Expand Down Expand Up @@ -175,6 +177,7 @@ public int ProcessResultsSet(DbDataReader reader)

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

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

for (var count = 0; count < maxRows && reader.Read(); count++)
if (isDebugLog)
Log.Debug("processing result set");

int count;
for (count = 0; count < maxRows && reader.Read(); count++)
{
if (isDebugLog)
Log.Debug("result set row: {0}", count);

rowCount++;

var o =
Expand All @@ -242,6 +252,9 @@ public int ProcessResultsSet(DbDataReader reader)
tmpResults.Add(o);
}

if (isDebugLog)
Log.Debug("done processing result set ({0} rows)", count);

queryInfo.Result = tmpResults;
if (queryInfo.CanPutToCache)
queryInfo.ResultToCache = new List<object>(tmpResults);
Expand Down

0 comments on commit 6784416

Please sign in to comment.