Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce contention by caching shellsetting accessors #15728

Merged
merged 3 commits into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions src/OrchardCore/OrchardCore.Abstractions/Shell/ShellSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ public class ShellSettings : IDisposable
private readonly ShellConfiguration _settings;
private readonly ShellConfiguration _configuration;
internal volatile int _shellCreating;
private bool _disposed;

private string _requestUrlPrefix;
private string _versionId;
private string _tenantId;
private string _requestUrlHost;
private string[] _requestUrlHosts;
private TenantState? _state;

/// <summary>
/// Initializes a new <see cref="ShellSettings"/>.
Expand Down Expand Up @@ -67,7 +73,7 @@ public ShellSettings(ShellSettings settings)
/// Whether this instance has been disposed or not.
/// </summary>
[JsonIgnore]
public bool Disposed => _disposed;
public bool Disposed { get; private set; }

/// <summary>
/// Whether this instance is disposable or not.
Expand All @@ -80,33 +86,33 @@ public ShellSettings(ShellSettings settings)
/// </summary>
public string VersionId
{
get => _settings["VersionId"];
get => _versionId ??= _settings["VersionId"];
set
{
_settings["TenantId"] ??= _settings["VersionId"] ?? value;
_settings["VersionId"] = value;
_versionId = _settings["VersionId"] = value;
}
}

/// <summary>
/// The tenant identifier.
/// </summary>
public string TenantId => _settings["TenantId"] ?? _settings["VersionId"];
public string TenantId => _tenantId ??= _settings["TenantId"] ?? _settings["VersionId"];

/// <summary>
/// The tenant request url host, multiple separated hosts may be provided.
/// </summary>
public string RequestUrlHost
{
get => _settings["RequestUrlHost"];
set => _settings["RequestUrlHost"] = value;
get => _requestUrlHost ??= _settings["RequestUrlHost"] ?? string.Empty;
set => _requestUrlHost = _settings["RequestUrlHost"] = value;
}

/// <summary>
/// The tenant request url host(s).
/// </summary>
[JsonIgnore]
public string[] RequestUrlHosts => _settings["RequestUrlHost"]
public string[] RequestUrlHosts => _requestUrlHosts ??= _settings["RequestUrlHost"]
?.Split(HostSeparators, StringSplitOptions.RemoveEmptyEntries)
?? [];

Expand All @@ -115,8 +121,8 @@ public string RequestUrlHost
/// </summary>
public string RequestUrlPrefix
{
get => _settings["RequestUrlPrefix"]?.Trim(' ', '/');
set => _settings["RequestUrlPrefix"] = value;
get => _requestUrlPrefix ??= _settings["RequestUrlPrefix"]?.Trim(' ', '/') ?? string.Empty;
set => _requestUrlPrefix = _settings["RequestUrlPrefix"] = value;
}

/// <summary>
Expand All @@ -125,8 +131,8 @@ public string RequestUrlPrefix
[JsonConverter(typeof(JsonStringEnumConverter))]
public TenantState State
{
get => _settings.GetValue<TenantState>("State");
set => _settings["State"] = value.ToString();
get => _state ??= _settings.GetValue<TenantState>("State");
set => _state = Enum.Parse<TenantState>(_settings["State"] = value.ToString());
}

/// <summary>
Expand Down Expand Up @@ -161,12 +167,12 @@ public void Dispose()

private void Close()
{
if (_disposed)
if (Disposed)
{
return;
}

_disposed = true;
Disposed = true;

_settings?.Release();
_configuration?.Release();
Expand Down
Loading