From 76e46d2fa72fa7cd18fee0936c1957172f2a438b Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Tue, 8 Dec 2020 14:43:39 +0900 Subject: [PATCH] Fix performance issues on query over orderId (fix #2114) --- BTCPayServer.Data/Data/InvoiceData.cs | 1 + .../20201208054211_invoicesorderindex.cs | 26 +++++++++++++++++++ .../ApplicationDbContextModelSnapshot.cs | 2 ++ 3 files changed, 29 insertions(+) create mode 100644 BTCPayServer.Data/Migrations/20201208054211_invoicesorderindex.cs diff --git a/BTCPayServer.Data/Data/InvoiceData.cs b/BTCPayServer.Data/Data/InvoiceData.cs index 4bfc065f7..04a53348f 100644 --- a/BTCPayServer.Data/Data/InvoiceData.cs +++ b/BTCPayServer.Data/Data/InvoiceData.cs @@ -85,6 +85,7 @@ namespace BTCPayServer.Data .HasOne(o => o.StoreData) .WithMany(a => a.Invoices).OnDelete(DeleteBehavior.Cascade); builder.Entity().HasIndex(o => o.StoreDataId); + builder.Entity().HasIndex(o => o.OrderId); builder.Entity() .HasOne(o => o.CurrentRefund); } diff --git a/BTCPayServer.Data/Migrations/20201208054211_invoicesorderindex.cs b/BTCPayServer.Data/Migrations/20201208054211_invoicesorderindex.cs new file mode 100644 index 000000000..3bc12a32f --- /dev/null +++ b/BTCPayServer.Data/Migrations/20201208054211_invoicesorderindex.cs @@ -0,0 +1,26 @@ +using BTCPayServer.Data; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace BTCPayServer.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20201208054211_invoicesorderindex")] + public partial class invoicesorderindex : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateIndex( + name: "IX_Invoices_OrderId", + table: "Invoices", + column: "OrderId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_Invoices_OrderId", + table: "Invoices"); + } + } +} diff --git a/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs b/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs index ff64ecef3..8041007cf 100644 --- a/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -228,6 +228,8 @@ namespace BTCPayServer.Migrations b.HasKey("Id"); + b.HasIndex("OrderId"); + b.HasIndex("StoreDataId"); b.HasIndex("Id", "CurrentRefundId");