perf: index form data exports
This commit is contained in:
parent
4683d09488
commit
d9730db6a9
@ -26,7 +26,7 @@ public class FormDataConfiguration : IEntityTypeConfiguration<FormData>
|
||||
builder.Property(e => e.OperatorIP).HasMaxLength(500).HasComment("操作人IP地址");
|
||||
|
||||
builder.HasIndex(e => e.InstanceId);
|
||||
builder.HasIndex(e => e.FormDefinitionId);
|
||||
builder.HasIndex(e => new { e.FormDefinitionId, e.CreatedAt, e.Id });
|
||||
|
||||
// GIN 索引支持对 DataJson 内容的 @> 包含查询
|
||||
builder.HasIndex(e => e.DataJson)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,36 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Workflow.Infrastructure.Persistence.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddFormDataExportKeysetIndex : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "ix_b_form_data_form_definition_id",
|
||||
table: "b_form_data");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_b_form_data_form_definition_id_created_at_id",
|
||||
table: "b_form_data",
|
||||
columns: new[] { "form_definition_id", "created_at", "id" });
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "ix_b_form_data_form_definition_id_created_at_id",
|
||||
table: "b_form_data");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_b_form_data_form_definition_id",
|
||||
table: "b_form_data",
|
||||
column: "form_definition_id");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -873,12 +873,12 @@ namespace BuildFlow.Workflow.Infrastructure.Persistence.Migrations
|
||||
NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("DataJson"), "GIN");
|
||||
NpgsqlIndexBuilderExtensions.HasOperators(b.HasIndex("DataJson"), new[] { "jsonb_path_ops" });
|
||||
|
||||
b.HasIndex("FormDefinitionId")
|
||||
.HasDatabaseName("ix_b_form_data_form_definition_id");
|
||||
|
||||
b.HasIndex("InstanceId")
|
||||
.HasDatabaseName("ix_b_form_data_instance_id");
|
||||
|
||||
b.HasIndex("FormDefinitionId", "CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_b_form_data_form_definition_id_created_at_id");
|
||||
|
||||
b.ToTable("b_form_data", (string)null);
|
||||
});
|
||||
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Workflow.Domain.Entities;
|
||||
using Xunit;
|
||||
|
||||
namespace BuildFlow.Workflow.Tests.Performance;
|
||||
|
||||
/// <summary>表单数据导出 keyset 查询的 EF 索引模型测试。</summary>
|
||||
public class FormDataExportIndexTests
|
||||
{
|
||||
[Fact]
|
||||
public void FormDataShouldHaveExportKeysetCompositeIndex()
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<WorkflowDbContext>()
|
||||
.UseInMemoryDatabase($"form-data-export-index-{Guid.NewGuid():N}")
|
||||
.Options;
|
||||
using var db = new WorkflowDbContext(options);
|
||||
var entity = db.Model.FindEntityType(typeof(FormData));
|
||||
|
||||
entity.Should().NotBeNull();
|
||||
entity!.GetIndexes().Should().Contain(index => index.Properties
|
||||
.Select(property => property.Name)
|
||||
.SequenceEqual(new[]
|
||||
{
|
||||
nameof(FormData.FormDefinitionId),
|
||||
nameof(FormData.CreatedAt),
|
||||
nameof(FormData.Id),
|
||||
}));
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user