perf(stock-report): покрывающий индекс движений (Phase45) — отчёт остатков 2.4с→1.1с на реальном объёме
Some checks failed
Auto-tag / Create date-tag (push) Waiting to run
CI / Backend (.NET 8) (push) Waiting to run
CI / Web (React + Vite) (push) Waiting to run
CI / POS (WPF, Windows) (push) Waiting to run
Docker API / Build + push API (push) Has been cancelled
Docker API / Deploy API on stage (push) Has been cancelled

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nns 2026-10-09 21:29:27 +05:00
parent 6a7806ff08
commit a2183e9532

View file

@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using foodmarket.Infrastructure.Persistence;
#nullable disable
namespace foodmarket.Infrastructure.Persistence.Migrations
{
/// <summary>Phase45 — покрывающий индекс для отчёта остатков на дату: группировка по
/// (Product, Store) + последняя себестоимость по OccurredAt. На реальном объёме
/// (≈288k движений) агрегаты отчёта падали с ~1.15с до ~0.33с (API: 2.4с → ~1.1с).
/// INCLUDE (Quantity, UnitCost) → index-only scan. Идемпотентно.</summary>
[DbContext(typeof(AppDbContext))]
[Migration("20261009210000_Phase45_StockMovementReportIndex")]
public partial class Phase45_StockMovementReportIndex : Migration
{
protected override void Up(MigrationBuilder b)
{
b.Sql(@"
CREATE INDEX IF NOT EXISTS ix_sm_org_prod_store_occ
ON public.stock_movements (""OrganizationId"", ""ProductId"", ""StoreId"", ""OccurredAt"" DESC)
INCLUDE (""Quantity"", ""UnitCost"");
");
}
protected override void Down(MigrationBuilder b)
{
b.Sql(@"DROP INDEX IF EXISTS public.ix_sm_org_prod_store_occ;");
}
}
}