refactor(kpi): K2/K6/K7 review fixups — empty-batch guard + sealed repo + uniform TryAddEnumerable + KPI-age doc fidelity + coverage

This commit is contained in:
Joseph Doherty
2026-06-17 20:00:43 -04:00
parent 456e61dff3
commit e6c15250ce
7 changed files with 46 additions and 8 deletions
@@ -10,7 +10,7 @@ namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Repositories;
/// <c>KpiSample</c> table (M6 "KPI History &amp; Trends"). See the interface for the
/// contract; this class adds notes on the data-access strategy per method.
/// </summary>
public class KpiHistoryRepository : IKpiHistoryRepository
public sealed class KpiHistoryRepository : IKpiHistoryRepository
{
private readonly ScadaBridgeDbContext _context;
@@ -29,6 +29,12 @@ public class KpiHistoryRepository : IKpiHistoryRepository
{
ArgumentNullException.ThrowIfNull(samples);
// Avoid a no-op SaveChanges round-trip on quiet sampling ticks.
if (samples.Count == 0)
{
return;
}
// Bulk-insert one sampling pass. AddRange + a single SaveChanges keeps the
// whole batch in one round-trip; the store assigns each row's identity.
_context.KpiSamples.AddRange(samples);