From 174e743904c1ebdab05df0a2ab662bbbc42d4db3 Mon Sep 17 00:00:00 2001 From: Nicolas Dorier Date: Wed, 18 May 2022 15:44:58 +0900 Subject: [PATCH] Improve invoice list performance (#3742) --- BTCPayServer.Data/Data/InvoiceData.cs | 1 + .../20220518061525_invoice_created_idx.cs | 28 ++++ .../ApplicationDbContextModelSnapshot.cs | 121 ++++++++++++------ 3 files changed, 112 insertions(+), 38 deletions(-) create mode 100644 BTCPayServer.Data/Migrations/20220518061525_invoice_created_idx.cs diff --git a/BTCPayServer.Data/Data/InvoiceData.cs b/BTCPayServer.Data/Data/InvoiceData.cs index e2d6ec239..ebff81828 100644 --- a/BTCPayServer.Data/Data/InvoiceData.cs +++ b/BTCPayServer.Data/Data/InvoiceData.cs @@ -43,6 +43,7 @@ namespace BTCPayServer.Data builder.Entity().HasIndex(o => o.OrderId); builder.Entity() .HasOne(o => o.CurrentRefund); + builder.Entity().HasIndex(o => o.Created); } } } diff --git a/BTCPayServer.Data/Migrations/20220518061525_invoice_created_idx.cs b/BTCPayServer.Data/Migrations/20220518061525_invoice_created_idx.cs new file mode 100644 index 000000000..47429305b --- /dev/null +++ b/BTCPayServer.Data/Migrations/20220518061525_invoice_created_idx.cs @@ -0,0 +1,28 @@ +using BTCPayServer.Data; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BTCPayServer.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20220518061525_invoice_created_idx")] + public partial class invoice_created_idx : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateIndex( + name: "IX_Invoices_Created", + table: "Invoices", + column: "Created"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_Invoices_Created", + table: "Invoices"); + } + } +} diff --git a/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs b/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs index 0abec6edc..188d429b9 100644 --- a/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/BTCPayServer.Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -1,4 +1,4 @@ -// +// using System; using BTCPayServer.Data; using Microsoft.EntityFrameworkCore; @@ -174,6 +174,61 @@ namespace BTCPayServer.Migrations b.ToTable("AspNetUsers", (string)null); }); + modelBuilder.Entity("BTCPayServer.Data.CustodianAccountData", b => + { + b.Property("Id") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Blob") + .HasColumnType("BLOB"); + + b.Property("CustodianCode") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Name") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("StoreId") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("StoreId"); + + b.ToTable("CustodianAccount"); + }); + + modelBuilder.Entity("BTCPayServer.Data.Data.PayoutProcessorData", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Blob") + .HasColumnType("BLOB"); + + b.Property("PaymentMethod") + .HasColumnType("TEXT"); + + b.Property("Processor") + .HasColumnType("TEXT"); + + b.Property("StoreId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("StoreId"); + + b.ToTable("PayoutProcessors"); + }); + modelBuilder.Entity("BTCPayServer.Data.Fido2Credential", b => { b.Property("Id") @@ -258,6 +313,8 @@ namespace BTCPayServer.Migrations b.HasKey("Id"); + b.HasIndex("Created"); + b.HasIndex("OrderId"); b.HasIndex("StoreDataId"); @@ -853,31 +910,6 @@ namespace BTCPayServer.Migrations b.ToTable("WebhookDeliveries"); }); - modelBuilder.Entity("BTCPayServer.PayoutProcessors.PayoutProcessorData", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("Blob") - .HasColumnType("BLOB"); - - b.Property("PaymentMethod") - .HasColumnType("TEXT"); - - b.Property("Processor") - .HasColumnType("TEXT"); - - b.Property("StoreId") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("StoreId"); - - b.ToTable("PayoutProcessors"); - }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => { b.Property("Id") @@ -1043,6 +1075,27 @@ namespace BTCPayServer.Migrations b.Navigation("StoreData"); }); + modelBuilder.Entity("BTCPayServer.Data.CustodianAccountData", b => + { + b.HasOne("BTCPayServer.Data.StoreData", "StoreData") + .WithMany("CustodianAccounts") + .HasForeignKey("StoreId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("StoreData"); + }); + + modelBuilder.Entity("BTCPayServer.Data.Data.PayoutProcessorData", b => + { + b.HasOne("BTCPayServer.Data.StoreData", "Store") + .WithMany("PayoutProcessors") + .HasForeignKey("StoreId") + .OnDelete(DeleteBehavior.Cascade); + + b.Navigation("Store"); + }); + modelBuilder.Entity("BTCPayServer.Data.Fido2Credential", b => { b.HasOne("BTCPayServer.Data.ApplicationUser", "ApplicationUser") @@ -1308,16 +1361,6 @@ namespace BTCPayServer.Migrations b.Navigation("Webhook"); }); - modelBuilder.Entity("BTCPayServer.PayoutProcessors.PayoutProcessorData", b => - { - b.HasOne("BTCPayServer.Data.StoreData", "Store") - .WithMany("PayoutProcessors") - .HasForeignKey("StoreId") - .OnDelete(DeleteBehavior.Cascade); - - b.Navigation("Store"); - }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) @@ -1414,6 +1457,8 @@ namespace BTCPayServer.Migrations b.Navigation("Apps"); + b.Navigation("CustodianAccounts"); + b.Navigation("Invoices"); b.Navigation("LightningAddresses"); @@ -1422,12 +1467,12 @@ namespace BTCPayServer.Migrations b.Navigation("PaymentRequests"); + b.Navigation("PayoutProcessors"); + b.Navigation("Payouts"); b.Navigation("PullPayments"); - b.Navigation("PayoutProcessors"); - b.Navigation("UserStores"); });