perf(templates): resync and resolved-members read only the chain/subtree (ScadaBridge#89)
The last two whole-library template reads are gone. Both fed the inheritance-only TemplateInheritanceResolver, which walks one template's parent chain and never follows compositions. - TemplateService.ResyncInheritedMembersAsync (operator repair, CLI + editor) now reads #86's GetTemplateReconcileClosureAsync (derived subtree + the template's chain, tracked). When nothing derives from the template the closure is empty, so it falls back to the new tracked GetTemplateChainAsync - resyncing a leaf reads only its own chain. - ManagementActor.HandleGetResolvedTemplateMembers now reads GetTemplateChainAsync(id, trackChanges: false): the chain alone, untracked, with script bodies (the resolver projects script code, so #66's body-free analysis closure would not be equivalent). The chain walk is factored out of TemplateReconcileClosure into CollectChainAsync (one load per level, stops on parent cycles and dangling parents) and shared by both. Evidence: - TemplateChainReadTests (#86 fixture): for every template plus an unknown id, the closure-backed resync issues exactly the writes, audit row and result of the whole-graph resync with GetAllTemplatesAsync wired to throw; the resolver answers identically from the chain and the whole graph. 17 of these fail against the old service; 13 fail with the leaf chain fallback removed (mutation-checked). - TemplateChainRepositoryTests (SQLite, recorded SQL): a 4-deep chain loads 4 templates / 8 attributes instead of 46 / 92, one split-query set per level, untracked on request and tracked for the resync. - ResolvedTemplateMembersReadTests: the actor answers from the untracked chain read and never calls GetAllTemplatesAsync (fails on the old actor). Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -20,17 +20,17 @@ namespace ZB.MOM.WW.ScadaBridge.TemplateEngine.Tests;
|
||||
/// </summary>
|
||||
public class TemplateReconcileClosureTests
|
||||
{
|
||||
private const int Root = 1, Base = 2, Mid = 3, Leaf1 = 4, Leaf2 = 5, Leaf3 = 6, GreatLeaf = 7, Mod = 8;
|
||||
private const int U1 = 9, U2 = 10, CycA = 11, CycB = 12, CycC = 13, Dang = 14, DangKid = 15;
|
||||
internal const int Root = 1, Base = 2, Mid = 3, Leaf1 = 4, Leaf2 = 5, Leaf3 = 6, GreatLeaf = 7, Mod = 8;
|
||||
internal const int U1 = 9, U2 = 10, CycA = 11, CycB = 12, CycC = 13, Dang = 14, DangKid = 15;
|
||||
|
||||
private static readonly JsonSerializerOptions Json = new()
|
||||
internal static readonly JsonSerializerOptions Json = new()
|
||||
{
|
||||
ReferenceHandler = ReferenceHandler.IgnoreCycles,
|
||||
WriteIndented = false,
|
||||
};
|
||||
|
||||
/// <summary>Builds a fresh, independently mutable copy of the fixture graph.</summary>
|
||||
private static List<Template> BuildGraph()
|
||||
internal static List<Template> BuildGraph()
|
||||
{
|
||||
var memberId = 1000;
|
||||
Template T(int id, string name, int? parent = null)
|
||||
@@ -112,7 +112,7 @@ public class TemplateReconcileClosureTests
|
||||
};
|
||||
}
|
||||
|
||||
private static Task<IReadOnlyList<Template>> Closure(
|
||||
internal static Task<IReadOnlyList<Template>> Closure(
|
||||
IReadOnlyList<Template> graph,
|
||||
int id,
|
||||
List<string>? calls = null) =>
|
||||
|
||||
Reference in New Issue
Block a user