Filter workflow summaries by latest version (#6132)

Ensure that only the latest version of each workflow definition is processed by grouping and selecting the highest version. This change helps prevent redundant updates and ensures data consistency.
This commit is contained in:
Sipke Schoorstra 2024-11-20 14:44:57 +01:00 committed by GitHub
parent c47157fd9f
commit 492b16bd24
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -118,11 +118,18 @@ public class WorkflowReferenceUpdater(
IsReadonly = false
};
var workflowDefinitionSummaries = await workflowDefinitionStore.FindSummariesAsync(workflowDefinitionFilter, cancellationToken);
// If there are workflow definition summaries with the same definition ID, only take the latest version.
workflowDefinitionSummaries = workflowDefinitionSummaries
.GroupBy(x => x.DefinitionId)
.Select(x => x.OrderByDescending(y => y.Version).First())
.ToList();
var workflowGraphs = new List<WorkflowGraph>();
foreach (var workflowDefinitionSummary in workflowDefinitionSummaries)
{
var workflowGraph = await workflowDefinitionService.FindWorkflowGraphAsync(workflowDefinitionSummary.DefinitionId, VersionOptions.LatestOrPublished, cancellationToken);
var workflowGraph = await workflowDefinitionService.FindWorkflowGraphAsync(workflowDefinitionSummary.Id, cancellationToken);
if (workflowGraph != null)
workflowGraphs.Add(workflowGraph);