Skip to content

Commit

Permalink
Possible multiple enumerations of IEnumerable collection new (#4158)
Browse files Browse the repository at this point in the history
* User story 100880 - Made changes from IEnumerable to IReadOnlyCollection

* ExportJobTask file changed

---------

Co-authored-by: Ajaj Vanu <[email protected]>
  • Loading branch information
v-ajajvanu and Ajaj Vanu authored Aug 28, 2024
1 parent 76698e7 commit 43e184c
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public override void Load()

_configurationProvider.Load();

IEnumerable<string> keys = _configurationProvider.GetChildKeys(Array.Empty<string>(), null);
var keys = _configurationProvider.GetChildKeys(Array.Empty<string>(), null).ToList();

var data = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

EnumerateKeys((IReadOnlyCollection<string>)keys, data);
EnumerateKeys(keys, data);

Data = data;
}
Expand Down Expand Up @@ -103,7 +103,7 @@ private void EnumerateKeys(IReadOnlyCollection<string> keys, Dictionary<string,
}
}

var innerKeys = (IReadOnlyCollection<string>)_configurationProvider.GetChildKeys(Array.Empty<string>(), keyPath);
var innerKeys = _configurationProvider.GetChildKeys(Array.Empty<string>(), keyPath).ToList();
EnumerateKeys(innerKeys, data, keyPath);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static class SearchServiceExtensions
throw new PreconditionFailedException(string.Format(CultureInfo.InvariantCulture, Core.Resources.ConditionalOperationNotSelectiveEnough, instanceType));
}

if (results?.Results.Any() == true)
if (results?.Results?.Any() == true)
{
matchedResults.AddRange(
results?.Results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal void ClearCache()
_evaluatedQueries.Clear();
}

public async Task<bool> SatisfiesAsync(IEnumerable<CapabilityQuery> queries, CancellationToken cancellationToken = default(CancellationToken))
public async Task<bool> SatisfiesAsync(IReadOnlyCollection<CapabilityQuery> queries, CancellationToken cancellationToken = default(CancellationToken))
{
EnsureArg.IsNotNull(queries, nameof(queries));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public interface IConformanceProvider
/// </summary>
/// <param name="queries">Query to check.</param>
/// <param name="cancellationToken">Cancellation token.</param>
Task<bool> SatisfiesAsync(IEnumerable<CapabilityQuery> queries, CancellationToken cancellationToken = default(CancellationToken));
Task<bool> SatisfiesAsync(IReadOnlyCollection<CapabilityQuery> queries, CancellationToken cancellationToken = default(CancellationToken));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public SystemConformanceProvider(

using (IScoped<IEnumerable<IProvideCapability>> providerFactory = _capabilityProviders())
{
IEnumerable<IProvideCapability> providers = providerFactory.Value;
var providers = providerFactory.Value.ToList();
foreach (IProvideCapability provider in providers)
{
Stopwatch watch = Stopwatch.StartNew();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,10 @@ private async Task SearchWithFilter(
|| string.IsNullOrWhiteSpace(_exportJobRecord.ResourceType)
|| _exportJobRecord.ResourceType.Contains(KnownResourceTypes.Patient, StringComparison.OrdinalIgnoreCase))
{
ProcessSearchResults(searchResult.Results, anonymizer);
ProcessSearchResults(searchResult?.Results.ToList(), anonymizer);
}

if (searchResult.ContinuationToken == null)
if (searchResult?.ContinuationToken == null)
{
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using EnsureThat;
Expand All @@ -27,7 +28,7 @@ public async Task Process(TRequest request, CancellationToken cancellationToken)
{
if (request is IRequireCapability provider)
{
if (!await _conformanceProvider.SatisfiesAsync(provider.RequiredCapabilities(), cancellationToken))
if (!await _conformanceProvider.SatisfiesAsync(provider.RequiredCapabilities().ToList(), cancellationToken))
{
throw new MethodNotAllowedException(Core.Resources.RequestedActionNotAllowed);
}
Expand Down

0 comments on commit 43e184c

Please sign in to comment.