From 4ba5633dc12a4ad359bc1487765413290fd99422 Mon Sep 17 00:00:00 2001 From: Joseph Weinkam Date: Tue, 4 Jun 2024 09:40:34 -0700 Subject: [PATCH] EMBCESSMOD-5523: calculate check compliance flags in parallel --- .../SupportCompliance/ISupportComplianceStrategy.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ess/src/API/EMBC.ESS/Engines/Supporting/SupportCompliance/ISupportComplianceStrategy.cs b/ess/src/API/EMBC.ESS/Engines/Supporting/SupportCompliance/ISupportComplianceStrategy.cs index 74c24935a..4a936ec90 100644 --- a/ess/src/API/EMBC.ESS/Engines/Supporting/SupportCompliance/ISupportComplianceStrategy.cs +++ b/ess/src/API/EMBC.ESS/Engines/Supporting/SupportCompliance/ISupportComplianceStrategy.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -44,11 +45,11 @@ public SupportComplianceStrategy(params ISupportComplianceCheck[] strategies) public async Task CheckCompliance(CheckSupportComplianceRequest request, CancellationToken ct = default) { - var flags = new Dictionary>(); - foreach (var support in request.Supports) + var flags = new ConcurrentDictionary>(); + await Parallel.ForEachAsync(request.Supports, ct, async (support, ct) => { - flags.Add(support, await CheckCompliance(support, ct)); - } + flags.TryAdd(support, await CheckCompliance(support, ct)); + }); return new CheckSupportComplianceResponse { Flags = flags