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

@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
@@ -21,6 +22,7 @@ using Tiku.Domain.Commerce;
using Tiku.Domain.Platform;
using Tiku.Domain.Tenancy;
using Tiku.IntegrationTests.Infrastructure;
using Tiku.Infrastructure.Bootstrap;
using Tiku.Infrastructure.Persistence;
namespace Tiku.IntegrationTests.Api;
@@ -34,7 +36,8 @@ public sealed class ApiTestFactory(
IDomainOwnershipVerifier? domainOwnershipVerifier = null,
IDomainGatewayProvisioner? domainGatewayProvisioner = null,
ISmsProvider? smsProvider = null,
IReadOnlyDictionary<string, string?>? configurationOverrides = null) : WebApplicationFactory<ApiProgramMarker>
IReadOnlyDictionary<string, string?>? configurationOverrides = null,
DbCommandInterceptor? dbCommandInterceptor = null) : WebApplicationFactory<ApiProgramMarker>
{
private readonly PostgresTestDatabase database = PostgresTestDatabase.Create();
@@ -88,6 +91,10 @@ public sealed class ApiTestFactory(
options.UseNpgsql(dataSource, npgsql =>
npgsql.MigrationsAssembly(typeof(TikuDbContext).Assembly.FullName));
options.AddInterceptors(serviceProvider.GetRequiredService<TenantIsolationSaveChangesInterceptor>());
if (dbCommandInterceptor is not null)
{
options.AddInterceptors(dbCommandInterceptor);
}
});
services.RemoveAll<IJwtKeyRing>();
services.AddSingleton<IJwtKeyRing, TestJwtKeyRing>();
@@ -315,6 +322,15 @@ public sealed class ApiTestFactory(
}
}
public async Task SeedBuiltinBackofficeCatalogAsync()
{
using var scope = Services.CreateScope();
scope.ServiceProvider.GetRequiredService<ITenantContextInitializer>()
.InitializeSystem(null, "Integration test built-in backoffice catalog seeding");
var dbContext = scope.ServiceProvider.GetRequiredService<TikuDbContext>();
await new BuiltinBackofficeCatalogSeeder(dbContext).SeedAsync();
}
private static async Task EnsureTenantBackendAccessAsync(
TikuDbContext dbContext,
IEnumerable<(Guid TenantId, Guid UserId)> members)