perf: remove backoffice catalog query amplification

This commit is contained in:
2026-07-30 09:50:05 +08:00
parent bedc77bffd
commit 98585aa521
8 changed files with 560 additions and 228 deletions

View File

@@ -0,0 +1,72 @@
using System.Collections.Concurrent;
using System.Data.Common;
using Microsoft.EntityFrameworkCore.Diagnostics;
namespace Tiku.IntegrationTests.Api;
internal sealed class RecordingDbCommandInterceptor : DbCommandInterceptor
{
private readonly ConcurrentQueue<string> commandTexts = new();
public IReadOnlyList<string> Snapshot() => commandTexts.ToArray();
public void Reset()
{
while (commandTexts.TryDequeue(out _))
{
}
}
public override DbDataReader ReaderExecuted(
DbCommand command,
CommandExecutedEventData eventData,
DbDataReader result)
{
Record(command);
return result;
}
public override ValueTask<DbDataReader> ReaderExecutedAsync(
DbCommand command,
CommandExecutedEventData eventData,
DbDataReader result,
CancellationToken cancellationToken = default)
{
Record(command);
return ValueTask.FromResult(result);
}
public override int NonQueryExecuted(DbCommand command, CommandExecutedEventData eventData, int result)
{
Record(command);
return result;
}
public override ValueTask<int> NonQueryExecutedAsync(
DbCommand command,
CommandExecutedEventData eventData,
int result,
CancellationToken cancellationToken = default)
{
Record(command);
return ValueTask.FromResult(result);
}
public override object? ScalarExecuted(DbCommand command, CommandExecutedEventData eventData, object? result)
{
Record(command);
return result;
}
public override ValueTask<object?> ScalarExecutedAsync(
DbCommand command,
CommandExecutedEventData eventData,
object? result,
CancellationToken cancellationToken = default)
{
Record(command);
return ValueTask.FromResult(result);
}
private void Record(DbCommand command) => commandTexts.Enqueue(command.CommandText);
}