perf(audit-log): bound GetExecutionTreeAsync edge scan to a root-anchored time window (partition elimination)
This commit is contained in:
+43
@@ -1008,6 +1008,49 @@ public class AuditLogRepositoryTests : IClassFixture<MsSqlMigrationFixture>
|
||||
}
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public async Task ExecutionTree_Bounds_EdgeScan_To_Root_Window()
|
||||
{
|
||||
Skip.IfNot(_fixture.Available, _fixture.SkipReason);
|
||||
|
||||
// arch-review 04 (P2): the down-walk Edges CTE is anchored to a
|
||||
// [rootFirst - 1h, rootFirst + 7d) window around the root's first event, enabling
|
||||
// partition elimination instead of a full-table DISTINCT scan. A genuine descendant
|
||||
// stamped BEYOND that 7-day span is excluded by design; a normal in-window child is
|
||||
// still returned.
|
||||
var siteId = NewSiteId();
|
||||
await using var context = CreateContext();
|
||||
var repo = new AuditLogRepository(context);
|
||||
|
||||
var rootExec = Guid.NewGuid();
|
||||
var childExec = Guid.NewGuid();
|
||||
var farDescendantExec = Guid.NewGuid();
|
||||
var unrelatedExec = Guid.NewGuid();
|
||||
|
||||
var t0 = new DateTime(2026, 10, 5, 9, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
// Root + an in-window child (T0 + 5 min) — both must be returned.
|
||||
await repo.InsertIfNotExistsAsync(NewEvent(siteId, occurredAtUtc: t0, executionId: rootExec));
|
||||
await repo.InsertIfNotExistsAsync(NewEvent(siteId, occurredAtUtc: t0.AddMinutes(5), executionId: childExec, parentExecutionId: rootExec));
|
||||
|
||||
// A genuine descendant of the child, but stamped 30 days out — beyond the 7-day
|
||||
// traversal bound, so it is documented-excluded from the tree.
|
||||
await repo.InsertIfNotExistsAsync(NewEvent(siteId, occurredAtUtc: t0.AddDays(30), executionId: farDescendantExec, parentExecutionId: childExec));
|
||||
|
||||
// An unrelated execution far in time sharing no ancestry — never part of the chain
|
||||
// (asserts the window bound does not accidentally pull in strangers).
|
||||
await repo.InsertIfNotExistsAsync(NewEvent(siteId, occurredAtUtc: t0.AddDays(30), executionId: unrelatedExec));
|
||||
|
||||
var tree = await repo.GetExecutionTreeAsync(rootExec);
|
||||
var ids = tree.Select(n => n.ExecutionId).ToHashSet();
|
||||
|
||||
Assert.Contains(rootExec, ids);
|
||||
Assert.Contains(childExec, ids);
|
||||
Assert.DoesNotContain(farDescendantExec, ids);
|
||||
Assert.DoesNotContain(unrelatedExec, ids);
|
||||
Assert.Equal(2, tree.Count);
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public async Task GetExecutionTree_StubParentNode()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user