40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
using System.Data.Common;
|
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
|
|
|
namespace BuildFlow.Workflow.Tests.Performance;
|
|
|
|
/// <summary>仅统计读取 b_form_data 的分页 SELECT 命令。</summary>
|
|
public sealed class CountingExportPageInterceptor : DbCommandInterceptor
|
|
{
|
|
/// <summary>已执行的表单数据分页查询数。</summary>
|
|
public int PageSelectCount { get; private set; }
|
|
|
|
public override InterceptionResult<DbDataReader> ReaderExecuting(
|
|
DbCommand command,
|
|
CommandEventData eventData,
|
|
InterceptionResult<DbDataReader> result)
|
|
{
|
|
Count(command);
|
|
return result;
|
|
}
|
|
|
|
public override ValueTask<InterceptionResult<DbDataReader>> ReaderExecutingAsync(
|
|
DbCommand command,
|
|
CommandEventData eventData,
|
|
InterceptionResult<DbDataReader> result,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
Count(command);
|
|
return ValueTask.FromResult(result);
|
|
}
|
|
|
|
private void Count(DbCommand command)
|
|
{
|
|
if (command.CommandText.TrimStart().StartsWith("SELECT", StringComparison.OrdinalIgnoreCase)
|
|
&& command.CommandText.Contains("b_form_data", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
PageSelectCount++;
|
|
}
|
|
}
|
|
}
|