Skip to content

Commit 64ea174

Browse files
committed
Add commits order index
1 parent 31dc78b commit 64ea174

4 files changed

Lines changed: 11 additions & 0 deletions

File tree

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@
2626
<PackageVersion Include="linq2db" Version="6.2.1" />
2727
<PackageVersion Include="linq2db.EntityFrameworkCore" Version="10.3.0" />
2828
<PackageVersion Include="linq2db.Extensions" Version="6.2.1" />
29+
<PackageVersion Include="EFCore.ComplexIndexes" Version="2.0.2" />
2930
</ItemGroup>
3031
</Project>

src/SIL.Harmony.Tests/DbContextTests.VerifyModel.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
Keys:
2525
Id PK
2626
Annotations:
27+
CustomIndex:CompositeIndexes: [{"paths":["HybridDateTime.DateTime","HybridDateTime.Counter","Id"],"unique":false,"name":"IX_Commits_DateTime_Counter_Id"}]
2728
Relational:FunctionName:
2829
Relational:Schema:
2930
Relational:SqlQuery:

src/SIL.Harmony/Db/EntityConfig/CommitEntityConfig.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Text.Json;
2+
using EFCore.ComplexIndexes;
23
using Microsoft.EntityFrameworkCore;
34
using Microsoft.EntityFrameworkCore.Metadata.Builders;
45

@@ -21,6 +22,13 @@ public void Configure(EntityTypeBuilder<Commit> builder)
2122
.HasColumnName("DateTime");
2223
hybridEntity.Property(h => h.Counter).HasColumnName("Counter");
2324
});
25+
// Supports Harmony's default ordering (DateTime DESC, Counter DESC, Id DESC).
26+
// EF Core 10 cannot express indexes mixing ComplexProperty members + scalars (efcore#11336, targeted for 11).
27+
// We use EFCore.ComplexIndexes instead. The package doesn't support column direction,
28+
// but an ASC index apparently works equivalently for reverse scans on SQLite, Postgres, and SQL Server.
29+
builder.HasComplexCompositeIndex(
30+
c => new { c.HybridDateTime.DateTime, c.HybridDateTime.Counter, c.Id },
31+
indexName: "IX_Commits_DateTime_Counter_Id");
2432
builder.Property(c => c.Metadata)
2533
.HasColumnType("jsonb")
2634
.HasConversion(

src/SIL.Harmony/SIL.Harmony.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
</PackageReference>
1717
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" />
18+
<PackageReference Include="EFCore.ComplexIndexes" />
1819
<PackageReference Include="Nito.AsyncEx.Coordination" />
1920
</ItemGroup>
2021

0 commit comments

Comments
 (0)