Skip to content

Commit

Permalink
Remove unnecessary async code (#15941)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienros authored May 2, 2024
1 parent c967b5d commit d3e6b32
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions src/OrchardCore/OrchardCore/Extensions/ExtensionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using OrchardCore.Environment.Extensions.Features;
Expand Down Expand Up @@ -37,7 +36,7 @@ public class ExtensionManager : IExtensionManager
private readonly ConcurrentDictionary<string, Lazy<IEnumerable<IFeatureInfo>>> _dependentFeatures = new();

private bool _isInitialized;
private readonly SemaphoreSlim _semaphore = new(1);
private readonly object _synLock = new();

public ExtensionManager(
IApplicationContext applicationContext,
Expand Down Expand Up @@ -81,7 +80,7 @@ public IEnumerable<IFeatureInfo> GetFeatures(string[] featureIdsToLoad)
EnsureInitialized();

var allDependencyIds = new HashSet<string>(featureIdsToLoad
.SelectMany(featureId => GetFeatureDependencies(featureId))
.SelectMany(GetFeatureDependencies)
.Select(x => x.Id));

foreach (var featureInfo in _featureInfos)
Expand All @@ -102,22 +101,22 @@ public Task<ExtensionEntry> LoadExtensionAsync(IExtensionInfo extensionInfo)
return Task.FromResult(extension);
}

public async Task<IEnumerable<FeatureEntry>> LoadFeaturesAsync()
public Task<IEnumerable<FeatureEntry>> LoadFeaturesAsync()
{
await EnsureInitializedAsync();
return _features.Values;
EnsureInitialized();
return Task.FromResult<IEnumerable<FeatureEntry>>(_features.Values);
}

public async Task<IEnumerable<FeatureEntry>> LoadFeaturesAsync(string[] featureIdsToLoad)
public Task<IEnumerable<FeatureEntry>> LoadFeaturesAsync(string[] featureIdsToLoad)
{
await EnsureInitializedAsync();
EnsureInitialized();

var features = new HashSet<string>(GetFeatures(featureIdsToLoad).Select(f => f.Id));

var loadedFeatures = _features.Values
.Where(f => features.Contains(f.FeatureInfo.Id));

return loadedFeatures;
return Task.FromResult<IEnumerable<FeatureEntry>>(loadedFeatures);
}

public IEnumerable<IFeatureInfo> GetFeatureDependencies(string featureId)
Expand Down Expand Up @@ -275,20 +274,8 @@ private void EnsureInitialized()
return;
}

EnsureInitializedAsync().GetAwaiter().GetResult();
}

private async Task EnsureInitializedAsync()
{
if (_isInitialized)
lock (_synLock)
{
return;
}

await _semaphore.WaitAsync();
try
{

if (_isInitialized)
{
return;
Expand Down Expand Up @@ -377,10 +364,6 @@ private async Task EnsureInitializedAsync()

_isInitialized = true;
}
finally
{
_semaphore.Release();
}
}

private static bool IsComponentType(Type type)
Expand Down

0 comments on commit d3e6b32

Please sign in to comment.