Make internal & private classes sealed where possible, to avoid code for virtual dispatch (#19719)
This commit is contained in:
@@ -14,7 +14,7 @@ namespace Umbraco.Cms.Infrastructure.HybridCache;
|
||||
/// <summary>
|
||||
/// Rebuilds the published content cache in the database.
|
||||
/// </summary>
|
||||
internal class DatabaseCacheRebuilder : IDatabaseCacheRebuilder
|
||||
internal sealed class DatabaseCacheRebuilder : IDatabaseCacheRebuilder
|
||||
{
|
||||
private const string NuCacheSerializerKey = "Umbraco.Web.PublishedCache.NuCache.Serializer";
|
||||
private const string IsRebuildingDatabaseCacheRuntimeCacheKey = "temp_database_cache_rebuild_op";
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Strings;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.HybridCache.Factories;
|
||||
|
||||
internal class CacheNodeFactory : ICacheNodeFactory
|
||||
internal sealed class CacheNodeFactory : ICacheNodeFactory
|
||||
{
|
||||
private readonly IShortStringHelper _shortStringHelper;
|
||||
private readonly UrlSegmentProviderCollection _urlSegmentProviders;
|
||||
private readonly IDocumentUrlService _documentUrlService;
|
||||
|
||||
public CacheNodeFactory(IShortStringHelper shortStringHelper, UrlSegmentProviderCollection urlSegmentProviders, IDocumentUrlService documentUrlService)
|
||||
public CacheNodeFactory(IShortStringHelper shortStringHelper, UrlSegmentProviderCollection urlSegmentProviders)
|
||||
{
|
||||
_shortStringHelper = shortStringHelper;
|
||||
_urlSegmentProviders = urlSegmentProviders;
|
||||
_documentUrlService = documentUrlService;
|
||||
}
|
||||
|
||||
public ContentCacheNode ToContentCacheNode(IContent content, bool preview)
|
||||
@@ -41,7 +38,7 @@ internal class CacheNodeFactory : ICacheNodeFactory
|
||||
};
|
||||
}
|
||||
|
||||
private bool GetPublishedValue(IContent content, bool preview)
|
||||
private static bool GetPublishedValue(IContent content, bool preview)
|
||||
{
|
||||
switch (content.PublishedState)
|
||||
{
|
||||
@@ -56,7 +53,7 @@ internal class CacheNodeFactory : ICacheNodeFactory
|
||||
}
|
||||
}
|
||||
|
||||
private int? GetTemplateId(IContent content, bool preview)
|
||||
private static int? GetTemplateId(IContent content, bool preview)
|
||||
{
|
||||
switch (content.PublishedState)
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@ using Umbraco.Cms.Core.PublishedCache;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.HybridCache.Factories;
|
||||
|
||||
internal class PublishedContentFactory : IPublishedContentFactory
|
||||
internal sealed class PublishedContentFactory : IPublishedContentFactory
|
||||
{
|
||||
private readonly IElementsCache _elementsCache;
|
||||
private readonly IVariationContextAccessor _variationContextAccessor;
|
||||
@@ -88,7 +88,7 @@ internal class PublishedContentFactory : IPublishedContentFactory
|
||||
return new PublishedMember(member, contentNode, _elementsCache, _variationContextAccessor);
|
||||
}
|
||||
|
||||
private Dictionary<string, PropertyData[]> GetPropertyValues(IPublishedContentType contentType, IMember member)
|
||||
private static Dictionary<string, PropertyData[]> GetPropertyValues(IPublishedContentType contentType, IMember member)
|
||||
{
|
||||
var properties = member
|
||||
.Properties
|
||||
@@ -111,7 +111,7 @@ internal class PublishedContentFactory : IPublishedContentFactory
|
||||
return properties;
|
||||
}
|
||||
|
||||
private void AddIf(IPublishedContentType contentType, IDictionary<string, PropertyData[]> properties, string alias, object? value)
|
||||
private static void AddIf(IPublishedContentType contentType, IDictionary<string, PropertyData[]> properties, string alias, object? value)
|
||||
{
|
||||
IPublishedPropertyType? propertyType = contentType.GetPropertyType(alias);
|
||||
if (propertyType == null || propertyType.IsUserProperty)
|
||||
@@ -135,14 +135,14 @@ internal class PublishedContentFactory : IPublishedContentFactory
|
||||
}
|
||||
|
||||
|
||||
private IPublishedContent? GetPublishedContentAsDraft(IPublishedContent? content) =>
|
||||
private static IPublishedContent? GetPublishedContentAsDraft(IPublishedContent? content) =>
|
||||
content == null ? null :
|
||||
// an object in the cache is either an IPublishedContentOrMedia,
|
||||
// or a model inheriting from PublishedContentExtended - in which
|
||||
// case we need to unwrap to get to the original IPublishedContentOrMedia.
|
||||
UnwrapIPublishedContent(content);
|
||||
|
||||
private PublishedContent UnwrapIPublishedContent(IPublishedContent content)
|
||||
private static PublishedContent UnwrapIPublishedContent(IPublishedContent content)
|
||||
{
|
||||
while (content is PublishedContentWrapped wrapped)
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ using Umbraco.Cms.Infrastructure.HybridCache.Services;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.HybridCache.NotificationHandlers;
|
||||
|
||||
internal class SeedingNotificationHandler : INotificationAsyncHandler<UmbracoApplicationStartedNotification>
|
||||
internal sealed class SeedingNotificationHandler : INotificationAsyncHandler<UmbracoApplicationStartedNotification>
|
||||
{
|
||||
private readonly IDocumentCacheService _documentCacheService;
|
||||
private readonly IMediaCacheService _mediaCacheService;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace Umbraco.Cms.Infrastructure.HybridCache.Persistence
|
||||
{
|
||||
// read-only dto
|
||||
internal class ContentSourceDto : IReadOnlyContentBase
|
||||
internal sealed class ContentSourceDto : IReadOnlyContentBase
|
||||
{
|
||||
public int Id { get; init; }
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Umbraco.Cms.Infrastructure.HybridCache;
|
||||
// note
|
||||
// the whole PublishedMember thing should be refactored because as soon as a member
|
||||
// is wrapped on in a model, the inner IMember and all associated properties are lost
|
||||
internal class PublishedMember : PublishedContent, IPublishedMember
|
||||
internal sealed class PublishedMember : PublishedContent, IPublishedMember
|
||||
{
|
||||
private readonly IMember _member;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.HybridCache;
|
||||
|
||||
internal class PublishedProperty : PublishedPropertyBase
|
||||
internal sealed class PublishedProperty : PublishedPropertyBase
|
||||
{
|
||||
private readonly PublishedContent _content;
|
||||
private readonly bool _isPreviewing;
|
||||
@@ -76,7 +76,7 @@ internal class PublishedProperty : PublishedPropertyBase
|
||||
// used to cache the CacheValues of this property
|
||||
internal string ValuesCacheKey => _valuesCacheKey ??= PropertyCacheValues(_content.Key, Alias, _isPreviewing);
|
||||
|
||||
private string PropertyCacheValues(Guid contentUid, string typeAlias, bool previewing)
|
||||
private static string PropertyCacheValues(Guid contentUid, string typeAlias, bool previewing)
|
||||
{
|
||||
if (previewing)
|
||||
{
|
||||
@@ -226,7 +226,7 @@ internal class PublishedProperty : PublishedPropertyBase
|
||||
return value;
|
||||
}
|
||||
|
||||
private object? GetDeliveryApiDefaultObject(CacheValue cacheValues, Func<object?> getValue)
|
||||
private static object? GetDeliveryApiDefaultObject(CacheValue cacheValues, Func<object?> getValue)
|
||||
{
|
||||
if (cacheValues.DeliveryApiDefaultObjectInitialized == false)
|
||||
{
|
||||
@@ -237,7 +237,7 @@ internal class PublishedProperty : PublishedPropertyBase
|
||||
return cacheValues.DeliveryApiDefaultObjectValue;
|
||||
}
|
||||
|
||||
private object? GetDeliveryApiExpandedObject(CacheValue cacheValues, Func<object?> getValue)
|
||||
private static object? GetDeliveryApiExpandedObject(CacheValue cacheValues, Func<object?> getValue)
|
||||
{
|
||||
if (cacheValues.DeliveryApiExpandedObjectInitialized == false)
|
||||
{
|
||||
@@ -248,7 +248,7 @@ internal class PublishedProperty : PublishedPropertyBase
|
||||
return cacheValues.DeliveryApiExpandedObjectValue;
|
||||
}
|
||||
|
||||
private class SourceInterValue
|
||||
private sealed class SourceInterValue
|
||||
{
|
||||
private string? _culture;
|
||||
private string? _segment;
|
||||
@@ -268,7 +268,7 @@ internal class PublishedProperty : PublishedPropertyBase
|
||||
public object? SourceValue { get; set; }
|
||||
}
|
||||
|
||||
private class CacheValues : CacheValue
|
||||
private sealed class CacheValues : CacheValue
|
||||
{
|
||||
private readonly Lock _locko = new();
|
||||
private ConcurrentDictionary<CompositeStringStringKey, CacheValue>? _values;
|
||||
|
||||
@@ -6,7 +6,7 @@ using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.HybridCache.Serialization;
|
||||
|
||||
internal class HybridCacheSerializer : IHybridCacheSerializer<ContentCacheNode>
|
||||
internal sealed class HybridCacheSerializer : IHybridCacheSerializer<ContentCacheNode>
|
||||
{
|
||||
private readonly ILogger<HybridCacheSerializer> _logger;
|
||||
private readonly MessagePackSerializerOptions _options;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Umbraco.Cms.Infrastructure.HybridCache.Serialization;
|
||||
/// <summary>
|
||||
/// Serializes/deserializes <see cref="ContentCacheDataModel" /> documents to the SQL Database as JSON.
|
||||
/// </summary>
|
||||
internal class JsonContentNestedDataSerializer : IContentCacheDataSerializer
|
||||
internal sealed class JsonContentNestedDataSerializer : IContentCacheDataSerializer
|
||||
{
|
||||
private static readonly JsonSerializerOptions _jsonSerializerOptions = new()
|
||||
{
|
||||
@@ -47,7 +47,7 @@ internal class JsonContentNestedDataSerializer : IContentCacheDataSerializer
|
||||
/// <summary>
|
||||
/// Provides a converter for handling JSON objects that can be of various types (string, number, boolean, null, or complex types).
|
||||
/// </summary>
|
||||
internal class JsonObjectConverter : JsonConverter<object>
|
||||
internal sealed class JsonObjectConverter : JsonConverter<object>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override object? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
@@ -65,5 +65,4 @@ internal class JsonContentNestedDataSerializer : IContentCacheDataSerializer
|
||||
public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOptions options)
|
||||
=> JsonSerializer.Serialize(writer, value, value.GetType(), options);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Umbraco.Cms.Infrastructure.HybridCache.Serialization;
|
||||
|
||||
internal class JsonContentNestedDataSerializerFactory : IContentCacheDataSerializerFactory
|
||||
internal sealed class JsonContentNestedDataSerializerFactory : IContentCacheDataSerializerFactory
|
||||
{
|
||||
private readonly Lazy<JsonContentNestedDataSerializer> _serializer = new();
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ using Umbraco.Cms.Core.Services;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.HybridCache.Serialization;
|
||||
|
||||
internal class MsgPackContentNestedDataSerializerFactory : IContentCacheDataSerializerFactory
|
||||
internal sealed class MsgPackContentNestedDataSerializerFactory : IContentCacheDataSerializerFactory
|
||||
{
|
||||
private readonly IPropertyCacheCompressionOptions _compressionOptions;
|
||||
private readonly IContentTypeService _contentTypeService;
|
||||
|
||||
@@ -13,7 +13,7 @@ using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.HybridCache.Services;
|
||||
|
||||
internal class MediaCacheService : IMediaCacheService
|
||||
internal sealed class MediaCacheService : IMediaCacheService
|
||||
{
|
||||
private readonly IDatabaseCacheRepository _databaseCacheRepository;
|
||||
private readonly IIdKeyMap _idKeyMap;
|
||||
|
||||
@@ -5,7 +5,7 @@ using Umbraco.Cms.Infrastructure.HybridCache.Factories;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.HybridCache.Services;
|
||||
|
||||
internal class MemberCacheService : IMemberCacheService
|
||||
internal sealed class MemberCacheService : IMemberCacheService
|
||||
{
|
||||
private readonly IPublishedContentFactory _publishedContentFactory;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user