refactor(kpi): K2/K6/K7 review fixups — empty-batch guard + sealed repo + uniform TryAddEnumerable + KPI-age doc fidelity + coverage
This commit is contained in:
+2
@@ -45,6 +45,8 @@ public class KpiSampleEntityTypeConfiguration : IEntityTypeConfiguration<KpiSamp
|
||||
|
||||
// Series index — backs the bucketed query path (filter one series, scan in
|
||||
// capture order). Names locked for migration discoverability.
|
||||
// Global-scope rows (ScopeKey IS NULL) are included in the index and are
|
||||
// seeked via the IS NULL predicate, so the index covers all scope levels.
|
||||
builder.HasIndex(s => new { s.Source, s.Metric, s.Scope, s.ScopeKey, s.CapturedAtUtc })
|
||||
.HasDatabaseName("IX_KpiSample_Series");
|
||||
|
||||
|
||||
+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