Optimize invoice performance with indexes and DTO
Added indexes for `ImportedAt` and a composite key on `InvoiceNumber` and `SellerTaxId` to improve query performance. Updated `AppDbContext` and EF Core migrations to reflect these changes. Introduced `ZugferdInvoiceListDto` to optimize memory usage by excluding large fields like `RawXml`. Updated the frontend (`Index.cshtml`) and backend (`Index.cshtml.cs`) to use the new DTO for better performance.
This commit is contained in:
@@ -6,4 +6,27 @@ namespace DXApp.TemplateKitProject.Data;
|
||||
public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
|
||||
{
|
||||
public DbSet<ZugferdInvoice> ZugferdInvoices { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.Entity<ZugferdInvoice>(entity =>
|
||||
{
|
||||
// Index für Performance-Optimierung der Rechnungsliste
|
||||
entity.HasIndex(e => e.ImportedAt)
|
||||
.HasDatabaseName("IX_ZugferdInvoices_ImportedAt");
|
||||
|
||||
// Index für Duplikatprüfung
|
||||
entity.HasIndex(e => new { e.InvoiceNumber, e.SellerTaxId })
|
||||
.HasDatabaseName("IX_ZugferdInvoices_InvoiceNumber_SellerTaxId");
|
||||
|
||||
// Decimal-Präzision explizit festlegen (behebt EF Core Warnung)
|
||||
entity.Property(e => e.TotalAmount)
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
entity.Property(e => e.TaxAmount)
|
||||
.HasColumnType("decimal(18,2)");
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user