From 6b2eea3502c21d7d852feacd314976a0859eb739 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Fri, 2 Feb 2024 21:38:51 +0100 Subject: [PATCH] Optimize activity execution contexts filtering Removed manual removal of child contexts from the list of active activity execution contexts. Replaced it with more efficient direct filtering of not completed activity execution contexts. This change may affect scripts that access activity output directly, but a variable capturing workaround is provided. --- .../Services/WorkflowStateExtractor.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/modules/Elsa.Workflows.Core/Services/WorkflowStateExtractor.cs b/src/modules/Elsa.Workflows.Core/Services/WorkflowStateExtractor.cs index bc2cdefab..9d95a4d4c 100644 --- a/src/modules/Elsa.Workflows.Core/Services/WorkflowStateExtractor.cs +++ b/src/modules/Elsa.Workflows.Core/Services/WorkflowStateExtractor.cs @@ -253,14 +253,9 @@ public class WorkflowStateExtractor : IWorkflowStateExtractor private static IEnumerable GetActiveActivityExecutionContexts(IEnumerable activityExecutionContexts) { - var contexts = activityExecutionContexts.ToList(); - - // Remove all child contexts of completed contexts. - foreach (var context in contexts.ToList().Where(context => context.IsCompleted)) - { - contexts.RemoveAll(x => x.ParentActivityExecutionContext == context); - } - - return contexts; + // Filter out completed activity execution contexts. + // This will currently break scripts accessing activity output directly, but there's a workaround for that via variable capturing. + // We may ultimately restore direct output access, but in a different way. + return activityExecutionContexts.Where(x => !x.IsCompleted).ToList(); } } \ No newline at end of file