perf(site-call-audit): filtered IX_SiteCalls_NonTerminal index — KPI predicates seek the live queue instead of scanning 365 days
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Audit;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Entities.ExternalSystems;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Notifications;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Sites;
|
||||
@@ -70,6 +73,27 @@ public class SchemaConfigurationTests : IDisposable
|
||||
|
||||
Assert.IsType<EncryptedStringConverter>(converter);
|
||||
}
|
||||
|
||||
// arch-review 04 (P1): the SiteCalls "live queue" KPI predicates all filter on
|
||||
// TerminalAtUtc IS NULL and run every 60 s (KPI recorder) + every 10 s (Health poll).
|
||||
// A filtered index over just the non-terminal rows turns each count from a clustered
|
||||
// scan of the 365-day archive into a small seek. Locked shape:
|
||||
// key = CreatedAtUtc, filter = [TerminalAtUtc] IS NULL, INCLUDE SourceSite/SourceNode/Status.
|
||||
[Fact]
|
||||
public void SiteCalls_Has_Filtered_NonTerminal_Index()
|
||||
{
|
||||
// IncludeProperties is a SQL-Server-only annotation stripped from the runtime
|
||||
// read-optimized model, so read the design-time model where it is preserved.
|
||||
var model = _context.GetService<IDesignTimeModel>().Model;
|
||||
var entity = model.FindEntityType(typeof(SiteCall))!;
|
||||
var index = entity.GetIndexes().Single(i => i.GetDatabaseName() == "IX_SiteCalls_NonTerminal");
|
||||
|
||||
Assert.Equal(new[] { nameof(SiteCall.CreatedAtUtc) }, index.Properties.Select(p => p.Name));
|
||||
Assert.Equal("[TerminalAtUtc] IS NULL", index.GetFilter());
|
||||
Assert.Equal(
|
||||
new[] { nameof(SiteCall.SourceSite), nameof(SiteCall.SourceNode), nameof(SiteCall.Status) },
|
||||
index.GetIncludeProperties());
|
||||
}
|
||||
}
|
||||
|
||||
public class SplitQueryBehaviourTests : IDisposable
|
||||
|
||||
Reference in New Issue
Block a user