Skip to content

Commit

Permalink
fix: improve performance for determining to be indexed values GRAR-1673
Browse files Browse the repository at this point in the history
  • Loading branch information
CumpsD committed Jan 7, 2021
1 parent 6a27672 commit 0f1dd14
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
]
},
"dotnet-ef": {
"version": "3.1.2",
"version": "5.0.1",
"commands": [
"dotnet-ef"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,13 @@ protected async Task<IEnumerable<LastChangedRecord>> GetLastChangedRecordsAndUpd

private static string GetApplicationType(AcceptType acceptType)
{
switch (acceptType)
return acceptType switch
{
case AcceptType.Json:
return "application/json";

case AcceptType.JsonLd:
return "application/ld+json";

case AcceptType.Xml:
return "application/xml";

default:
return string.Empty;
}
AcceptType.Json => "application/json",
AcceptType.JsonLd => "application/ld+json",
AcceptType.Xml => "application/xml",
_ => string.Empty
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder
.Entity<LastChangedRecord>()
.Property(x => x.ToBeIndexed)
.ValueGeneratedOnAddOrUpdate()
.HasComputedColumnSql("CAST(CASE WHEN (([Position] > [LastPopulatedPosition]) AND ([ErrorCount] < 10)) THEN 1 ELSE 0 END AS bit) PERSISTED");

modelBuilder
.Entity<LastChangedRecord>()
.HasIndex(x => x.ToBeIndexed)
.IncludeProperties(x => x.LastError);

modelBuilder
.Entity<LastChangedRecord>()
.HasIndex(x => x.Position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ namespace Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList
public class LastChangedListContextMigrationFactory : RunnerDbContextMigrationFactory<LastChangedListContext> {

public LastChangedListContextMigrationFactory(string connectionStringName)
: base(connectionStringName, HistoryConfiguration)
{ }
: base(connectionStringName, HistoryConfiguration) { }

private static MigrationHistoryConfiguration HistoryConfiguration =>
new MigrationHistoryConfiguration
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList.Migrations
{
public partial class AddToBeIndexed : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "ToBeIndexed",
schema: "Redis",
table: "LastChangedList",
type: "bit",
nullable: false,
computedColumnSql: "CAST(CASE WHEN (([Position] > [LastPopulatedPosition]) AND ([ErrorCount] < 10)) THEN 1 ELSE 0 END AS bit) PERSISTED");

migrationBuilder.CreateIndex(
name: "IX_LastChangedList_ToBeIndexed",
schema: "Redis",
table: "LastChangedList",
column: "ToBeIndexed")
.Annotation("SqlServer:Include", new[] { "LastError" });
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_LastChangedList_ToBeIndexed",
schema: "Redis",
table: "LastChangedList");

migrationBuilder.DropColumn(
name: "ToBeIndexed",
schema: "Redis",
table: "LastChangedList");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("Redis")
.HasAnnotation("ProductVersion", "3.1.8")
.UseIdentityColumns()
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
.HasAnnotation("ProductVersion", "5.0.1");

modelBuilder.Entity("Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList.Model.LastChangedRecord", b =>
{
Expand Down Expand Up @@ -46,11 +46,16 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<long>("Position")
.HasColumnType("bigint");
b.Property<bool>("ToBeIndexed")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("bit")
.HasComputedColumnSql("CAST(CASE WHEN (([Position] > [LastPopulatedPosition]) AND ([ErrorCount] < 10)) THEN 1 ELSE 0 END AS bit) PERSISTED");
b.Property<string>("Uri")
.HasColumnType("nvarchar(max)");
b.HasKey("Id")
.HasAnnotation("SqlServer:Clustered", true);
.IsClustered();
b.HasIndex("CacheKey");
Expand All @@ -60,6 +65,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasIndex("Position");
b.HasIndex("ToBeIndexed")
.IncludeProperties(new[] { "LastError" });
b.HasIndex("Position", "LastPopulatedPosition", "ErrorCount", "LastError");
b.ToTable("LastChangedList");
Expand All @@ -83,9 +91,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("bigint");
b.HasKey("Name")
.HasAnnotation("SqlServer:Clustered", true);
.IsClustered();
b.ToTable("ProjectionStates","Redis");
b.ToTable("ProjectionStates", "Redis");
});
#pragma warning restore 612, 618
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public class LastChangedRecord
public int ErrorCount { get; set; }
public DateTimeOffset? LastError { get; set; }
public string? LastErrorMessage { get; set; }

public bool ToBeIndexed { get; private set; }
}
}
2 changes: 1 addition & 1 deletion src/EF.MigrationsHelper/EF.MigrationHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net5.0</TargetFramework>
<LangVersion>latest</LangVersion>

<RuntimeFrameworkVersion>3.1.0</RuntimeFrameworkVersion>
<RuntimeFrameworkVersion>5.0.1</RuntimeFrameworkVersion>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<OutputType>Exe</OutputType>

Expand Down

0 comments on commit 0f1dd14

Please sign in to comment.