refactor(kpi): K2/K6/K7 review fixups — empty-batch guard + sealed repo + uniform TryAddEnumerable + KPI-age doc fidelity + coverage
This commit is contained in:
+7
-1
@@ -10,7 +10,7 @@ namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Repositories;
|
||||
/// <c>KpiSample</c> table (M6 "KPI History & 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);
|
||||
|
||||
Reference in New Issue
Block a user