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:
+24
@@ -476,6 +476,30 @@ public class TemplateEngineRepository : ITemplateEngineRepository
|
||||
.FirstOrDefaultAsync(i => i.UniqueName == uniqueName, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IReadOnlyList<Instance>> GetInstancesByUniqueNamesAsync(
|
||||
IEnumerable<string> uniqueNames, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// Bulk variant for the bundle importer's preview + instance pass, which used to
|
||||
// call GetInstanceByUniqueNameAsync once per bundled instance (review 2026-10-21
|
||||
// 04/P4). De-duplicate before the query so EF emits a clean IN list.
|
||||
if (uniqueNames is null) return Array.Empty<Instance>();
|
||||
var distinct = uniqueNames
|
||||
.Where(n => !string.IsNullOrEmpty(n))
|
||||
.Distinct(StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
if (distinct.Length == 0) return Array.Empty<Instance>();
|
||||
|
||||
return await _context.Instances
|
||||
.Where(i => distinct.Contains(i.UniqueName))
|
||||
.Include(i => i.AttributeOverrides)
|
||||
.Include(i => i.AlarmOverrides)
|
||||
.Include(i => i.ConnectionBindings)
|
||||
.Include(i => i.NativeAlarmSourceOverrides)
|
||||
.AsSplitQuery()
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task AddInstanceAsync(Instance instance, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user