fix(centralui): bound FlowDebugService script cache (review 2026-10-21 07/M-2)

This commit is contained in:
Joseph Doherty
2026-10-22 08:37:20 -04:00
parent bd0f87e523
commit b032d7fe48
2 changed files with 29 additions and 0 deletions
@@ -107,6 +107,13 @@ public sealed class FlowDebugService : IFlowDebugService
/// </summary>
private readonly Dictionary<int, InstanceScripts> _scriptCache = new();
/// <summary>
/// Ceiling on <see cref="_scriptCache"/> entries (review 2026-10-21 07/M-2). Only the most
/// recently selected instance is ever read back, so a small bound loses nothing; reaching it
/// drops the whole cache before the new entry goes in.
/// </summary>
internal const int ScriptCacheCapacity = 8;
/// <summary>One instance's flattened scripts: the unique name the site keys on, the raw resolved scripts, and the picker projection.</summary>
private sealed record InstanceScripts(
string UniqueName,
@@ -484,6 +491,10 @@ public sealed class FlowDebugService : IFlowDebugService
.ToList();
var loaded = new InstanceScripts(instance.UniqueName, scripts, options);
if (_scriptCache.Count >= ScriptCacheCapacity && !_scriptCache.ContainsKey(instanceId))
{
_scriptCache.Clear();
}
_scriptCache[instanceId] = loaded;
return loaded;
}