fix(transport): import reads the template library once per session, batches instance lookups, and expands stale instances to derived/composing templates over one flatten session (review 2026-10-21 04/P4, 08/P1, 04/C2)

This commit is contained in:
Joseph Doherty
2026-10-22 09:36:34 -04:00
parent 39025b28fa
commit 7e08a1dbfb
8 changed files with 723 additions and 109 deletions
@@ -262,6 +262,15 @@ public interface ITemplateEngineRepository
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>A task that resolves to the matching instance, or <see langword="null"/> if not found.</returns>
Task<Instance?> GetInstanceByUniqueNameAsync(string uniqueName, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves every instance whose unique name is in <paramref name="uniqueNames"/>, with the
/// same four child collections <see cref="GetInstanceByUniqueNameAsync"/> includes, in one
/// round trip (tracked). Unknown names are simply absent from the result.
/// </summary>
/// <param name="uniqueNames">The unique instance names to look up; null/empty/duplicate entries are ignored.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>A task that resolves to the matching instances.</returns>
Task<IReadOnlyList<Instance>> GetInstancesByUniqueNamesAsync(IEnumerable<string> uniqueNames, CancellationToken cancellationToken = default);
/// <summary>Adds a new instance.</summary>
/// <param name="instance">The instance to add.</param>
/// <param name="cancellationToken">Cancellation token.</param>
@@ -29,4 +29,14 @@ public interface IStaleInstanceProbe
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>The current revision hash (e.g. <c>sha256:...</c>), or <c>null</c>.</returns>
Task<string?> GetCurrentRevisionHashAsync(int instanceId, CancellationToken cancellationToken = default);
/// <summary>
/// Returns a probe for hashing a batch of instances that may share template
/// chains — the implementation can reuse one flatten session across the batch so
/// a chain is walked once, not once per instance (review 2026-10-21 04/C2). Use
/// the returned probe for one batch only, within the caller's scope. The default
/// is this probe itself (no sharing).
/// </summary>
/// <returns>A probe to use for the batch.</returns>
IStaleInstanceProbe BeginBatch() => this;
}