perf(deployment,template-engine): batched untracked staleness loads, staging-failure detach, lock-held Disabled re-check, targeted single-entity loads (DEP-4, DEP-5, DEP-6, TPL-4, WP6 task 6.6)
DEP-4: new ITemplateEngineRepository.GetInstancesByIdsUntrackedAsync (one
AsNoTracking split query per 500-id chunk). GetInstanceStalenessAsync preloads
each chunk into its FlattenSession; FlattenCoreAsync takes a preloaded
instance (consumed once) before falling back to the tracked per-instance load.
Deploy sessions never preload, so prepare keeps its tracked load.
Throwaway harness, SQLite, 1,000 instances x 50 overrides:
before: 5,000 reader commands, 51,000 tracked entities
after: 10 reader commands, 0 tracked entities
(wall time on in-process SQLite 2.7 s -> 2.3 s; the win on SQL Server is
the 4,990 saved round-trips and the change tracker staying empty)
DEP-5: AddPendingDeploymentAsync supersedes prior rows with a set-based
delete (DeletePendingWhereAsync) instead of tracked key stubs, and a failed
staging save calls DetachPendingChanges under dbGate so it cannot poison the
next instance's staging save on the shared bulk context.
Regression: prior row purged between supersede and save -> before:
DbUpdateConcurrencyException; after: stages cleanly.
DEP-6: bulk prepare (reconcileGate != null) re-reads the instance state
untracked (new IDeploymentManagerRepository.GetInstanceStateAsync) once the
operation lock is held; Disabled -> reported in SkippedInstances with the
Disabled reason, never flattened/sent/re-enabled. Placed at the top of
PrepareUnderLockAsync so it is independent of WP7's lock-ordering change.
TPL-4: area delete uses the new shallow untracked GetInstancesBySiteIdShallowAsync;
SetAlarmOverride and Delete{Attribute,Alarm,Script} read the analysis closure
instead of the whole template table; MoveTemplate's collision check is the new
TemplateNameExistsInFolderAsync (one folder's names). SiteService already used
the include-free ISiteRepository read (unchanged).
This commit is contained in:
@@ -247,7 +247,9 @@ public class InstanceService
|
||||
// rule for a composed alarm. Mirrors SetAttributeOverrideAsync.
|
||||
// The resolver reads member names and lock flags only, so the no-tracking,
|
||||
// script-body-free analysis projection suffices (review 2026-10-21 04/P6, 08/P1).
|
||||
var allTemplates = await _repository.GetAllTemplatesForAnalysisAsync(cancellationToken);
|
||||
// TPL-4: the template's analysis closure (chain + compositions) is all the resolver
|
||||
// walks — not the whole template table.
|
||||
var allTemplates = await _repository.GetTemplateAnalysisClosureAsync(instance.TemplateId, cancellationToken);
|
||||
var resolvedAlarm = TemplateResolver
|
||||
.ResolveAllMembers(instance.TemplateId, allTemplates)
|
||||
.FirstOrDefault(m => m.MemberType == "Alarm" && m.CanonicalName == alarmCanonicalName);
|
||||
|
||||
Reference in New Issue
Block a user