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:
OlgunR
2026-06-02 13:45:57 +02:00
parent 2ae2bbdaf6
commit 03599addb8
7 changed files with 236 additions and 4 deletions

View File

@@ -12,7 +12,7 @@
}
else
{
@(Html.DevExtreme().DataGrid<DXApp.TemplateKitProject.Models.ZugferdInvoice>()
@(Html.DevExtreme().DataGrid<DXApp.TemplateKitProject.Models.ZugferdInvoiceListDto>()
.DataSource(Model.Invoices)
.KeyExpr("Id")
.ShowBorders(true)

View File

@@ -7,12 +7,30 @@ namespace DXApp.TemplateKitProject.Pages.Invoices;
public class IndexModel(AppDbContext db) : PageModel
{
public List<ZugferdInvoice> Invoices { get; private set; } = [];
public List<ZugferdInvoiceListDto> Invoices { get; private set; } = [];
public async Task OnGetAsync()
{
Invoices = await db.ZugferdInvoices
.OrderByDescending(i => i.ImportedAt)
.Select(i => new ZugferdInvoiceListDto
{
Id = i.Id,
InvoiceNumber = i.InvoiceNumber,
InvoiceDate = i.InvoiceDate,
SellerName = i.SellerName,
SellerTaxId = i.SellerTaxId,
BuyerName = i.BuyerName,
TotalAmount = i.TotalAmount,
TaxAmount = i.TaxAmount,
CurrencyCode = i.CurrencyCode,
Iban = i.Iban,
ImportedAt = i.ImportedAt,
SourceType = i.SourceType,
ResultFilePath = i.ResultFilePath,
GuidelineId = i.GuidelineId
// RawXml wird NICHT geladen ? Performance-Optimierung!
})
.ToListAsync();
}
}