Cleans up code - removes tuples everywhere
This commit is contained in:
@@ -7,7 +7,8 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
{
|
||||
public class AppSettingsNuCachePropertyMapFactory : INuCachePropertyOptionsFactory
|
||||
// TODO: We'll remove this when the responsibility for compressing property data is at the property editor level
|
||||
internal class AppSettingsNuCachePropertyMapFactory : INuCachePropertyOptionsFactory
|
||||
{
|
||||
public NuCachePropertyOptions GetNuCachePropertyOptions()
|
||||
{
|
||||
@@ -20,9 +21,9 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
return options;
|
||||
}
|
||||
|
||||
public IReadOnlyDictionary<string, (NucachePropertyCompressionLevel compress, NucachePropertyDecompressionLevel decompressionLevel, string mappedAlias)> GetPropertyMap()
|
||||
public IReadOnlyDictionary<string, NuCacheCompressionOptions> GetPropertyMap()
|
||||
{
|
||||
var propertyMap = new Dictionary<string, (NucachePropertyCompressionLevel compress, NucachePropertyDecompressionLevel decompressionLevel, string mappedAlias)>();
|
||||
var propertyMap = new Dictionary<string, NuCacheCompressionOptions>();
|
||||
// TODO: Use xml/json/c# to define map
|
||||
var propertyDictionarySerializerMap = ConfigurationManager.AppSettings["Umbraco.Web.PublishedCache.NuCache.PropertySerializationMap"];
|
||||
if (!string.IsNullOrWhiteSpace(propertyDictionarySerializerMap))
|
||||
@@ -39,7 +40,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
);
|
||||
return v;
|
||||
})
|
||||
.ToList().ForEach(x => propertyMap.Add(x.alias, (x.compressionLevel, x.decompressionLevel, x.mappedAlias)));
|
||||
.ToList().ForEach(x => propertyMap.Add(x.alias, new NuCacheCompressionOptions(x.compressionLevel, x.decompressionLevel, x.mappedAlias)));
|
||||
}
|
||||
return propertyMap;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
{
|
||||
None = 0,
|
||||
SQLDatabase = 1,
|
||||
NucacheDatabase = 2
|
||||
NuCacheDatabase = 2
|
||||
}
|
||||
/// <summary>
|
||||
/// If/where to decompress custom properties for nucache
|
||||
@@ -28,22 +28,22 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
Lazy = 2
|
||||
}
|
||||
|
||||
|
||||
|
||||
internal class Lz4DictionaryOfPropertyDataSerializer : SerializerBase, ISerializer<IDictionary<string, PropertyData[]>>, IDictionaryOfPropertyDataSerializer
|
||||
{
|
||||
private readonly IReadOnlyDictionary<string, (NucachePropertyCompressionLevel compress, NucachePropertyDecompressionLevel decompressionLevel, string mappedAlias)> _compressProperties;
|
||||
private readonly IReadOnlyDictionary<string, (NucachePropertyCompressionLevel compress, NucachePropertyDecompressionLevel decompressionLevel, string mappedAlias)> _uncompressProperties;
|
||||
private readonly IReadOnlyDictionary<string, NuCacheCompressionOptions> _compressProperties;
|
||||
private readonly IReadOnlyDictionary<string, NuCacheCompressionOptions> _uncompressProperties;
|
||||
|
||||
|
||||
public Lz4DictionaryOfPropertyDataSerializer(INuCachePropertyOptionsFactory nucachePropertyOptionsFactory)
|
||||
{
|
||||
var nucachePropertyOptions = nucachePropertyOptionsFactory.GetNuCachePropertyOptions();
|
||||
_compressProperties = nucachePropertyOptions.PropertyMap.ToList().ToDictionary(x => string.Intern(x.Key), x => (x.Value.compress,x.Value.decompressionLevel, string.Intern(x.Value.mappedAlias)));
|
||||
_uncompressProperties = _compressProperties.ToList().ToDictionary(x => x.Value.mappedAlias, x => (x.Value.compress, x.Value.decompressionLevel, x.Key));
|
||||
_compressProperties = nucachePropertyOptions.PropertyMap.ToList().ToDictionary(x => string.Intern(x.Key), x => new NuCacheCompressionOptions(x.Value.CompressLevel, x.Value.DecompressLevel, string.Intern(x.Value.MappedAlias)));
|
||||
_uncompressProperties = _compressProperties.ToList().ToDictionary(x => x.Value.MappedAlias, x => new NuCacheCompressionOptions(x.Value.CompressLevel, x.Value.DecompressLevel, x.Key));
|
||||
|
||||
_nucachePropertyOptions = nucachePropertyOptions;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public IDictionary<string, PropertyData[]> ReadFrom(Stream stream)
|
||||
{
|
||||
@@ -82,11 +82,11 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
pdata.Segment = ReadStringObject(stream, true) ?? string.Empty;
|
||||
pdata.Value = ReadObject(stream);
|
||||
|
||||
if ((map.Compress.Equals(NucachePropertyCompressionLevel.NucacheDatabase) || map.Compress.Equals(NucachePropertyCompressionLevel.SQLDatabase))
|
||||
if ((map.CompressLevel.Equals(NucachePropertyCompressionLevel.NuCacheDatabase) || map.CompressLevel.Equals(NucachePropertyCompressionLevel.SQLDatabase))
|
||||
&& pdata.Value != null && pdata.Value is byte[] byteArrayValue)
|
||||
{
|
||||
//Compressed string
|
||||
switch (map.decompressionLevel)
|
||||
switch (map.DecompressLevel)
|
||||
{
|
||||
case NucachePropertyDecompressionLevel.Lazy:
|
||||
pdata.Value = new LazyCompressedString(byteArrayValue);
|
||||
@@ -132,7 +132,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
WriteObject(pdata.Segment ?? string.Empty, stream);
|
||||
|
||||
//Only compress strings
|
||||
if (pdata.Value is string stringValue && pdata.Value != null && map.Compress.Equals(NucachePropertyCompressionLevel.NucacheDatabase)
|
||||
if (pdata.Value is string stringValue && pdata.Value != null && map.CompressLevel.Equals(NucachePropertyCompressionLevel.NuCacheDatabase)
|
||||
&& (_nucachePropertyOptions.MinimumCompressibleStringLength == null
|
||||
|| !_nucachePropertyOptions.MinimumCompressibleStringLength.HasValue
|
||||
|| stringValue.Length > _nucachePropertyOptions.MinimumCompressibleStringLength.Value))
|
||||
@@ -145,33 +145,33 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
}
|
||||
}
|
||||
}
|
||||
private readonly (NucachePropertyCompressionLevel Compress, NucachePropertyDecompressionLevel decompressionLevel, string MappedAlias) DEFAULT_MAP =(NucachePropertyCompressionLevel.None, NucachePropertyDecompressionLevel.NotCompressed, null);
|
||||
private static readonly NuCacheCompressionOptions DefaultMap = new NuCacheCompressionOptions(NucachePropertyCompressionLevel.None, NucachePropertyDecompressionLevel.NotCompressed, null);
|
||||
private readonly NuCachePropertyOptions _nucachePropertyOptions;
|
||||
|
||||
public (NucachePropertyCompressionLevel Compress, NucachePropertyDecompressionLevel decompressionLevel, string MappedAlias) GetSerializationMap(string propertyAlias)
|
||||
public NuCacheCompressionOptions GetSerializationMap(string propertyAlias)
|
||||
{
|
||||
if (_compressProperties == null)
|
||||
{
|
||||
return DEFAULT_MAP;
|
||||
return DefaultMap;
|
||||
}
|
||||
if (_compressProperties.TryGetValue(propertyAlias, out (NucachePropertyCompressionLevel compress, NucachePropertyDecompressionLevel decompressionLevel, string mappedAlias) map))
|
||||
if (_compressProperties.TryGetValue(propertyAlias, out var map1))
|
||||
{
|
||||
return map;
|
||||
return map1;
|
||||
}
|
||||
|
||||
return DEFAULT_MAP;
|
||||
return DefaultMap;
|
||||
}
|
||||
public (NucachePropertyCompressionLevel Compress, NucachePropertyDecompressionLevel decompressionLevel, string MappedAlias) GetDeSerializationMap(string propertyAlias)
|
||||
public NuCacheCompressionOptions GetDeSerializationMap(string propertyAlias)
|
||||
{
|
||||
if (_uncompressProperties == null)
|
||||
{
|
||||
return DEFAULT_MAP;
|
||||
return DefaultMap;
|
||||
}
|
||||
if (_uncompressProperties.TryGetValue(propertyAlias, out (NucachePropertyCompressionLevel compress, NucachePropertyDecompressionLevel decompressionLevel, string mappedAlias) map))
|
||||
if (_uncompressProperties.TryGetValue(propertyAlias, out var map2))
|
||||
{
|
||||
return map;
|
||||
return map2;
|
||||
}
|
||||
return DEFAULT_MAP;
|
||||
return DefaultMap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
{
|
||||
foreach (var map in _propertyOptions.PropertyMap)
|
||||
{
|
||||
if (map.Value.compress.Equals(NucachePropertyCompressionLevel.SQLDatabase))
|
||||
if (map.Value.CompressLevel.Equals(NucachePropertyCompressionLevel.SQLDatabase))
|
||||
{
|
||||
if (nestedData.PropertyData.TryGetValue(map.Key, out PropertyData[] properties))
|
||||
{
|
||||
@@ -79,11 +79,11 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
}
|
||||
}
|
||||
}
|
||||
if (map.Value.mappedAlias != null && !map.Key.Equals(map.Value.mappedAlias)
|
||||
if (map.Value.MappedAlias != null && !map.Key.Equals(map.Value.MappedAlias)
|
||||
&& nestedData.PropertyData.Remove(map.Key) && nestedData.PropertyData.TryGetValue(map.Key, out PropertyData[] properties2))
|
||||
{
|
||||
nestedData.PropertyData.Remove(map.Key);
|
||||
nestedData.PropertyData.Add(map.Value.mappedAlias, properties2);
|
||||
nestedData.PropertyData.Add(map.Value.MappedAlias, properties2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
{
|
||||
public struct NuCacheCompressionOptions : IEquatable<NuCacheCompressionOptions>
|
||||
{
|
||||
public NuCacheCompressionOptions(NucachePropertyCompressionLevel compressLevel, NucachePropertyDecompressionLevel decompressLevel, string mappedAlias)
|
||||
{
|
||||
CompressLevel = compressLevel;
|
||||
DecompressLevel = decompressLevel;
|
||||
MappedAlias = mappedAlias ?? throw new ArgumentNullException(nameof(mappedAlias));
|
||||
}
|
||||
|
||||
public NucachePropertyCompressionLevel CompressLevel { get; private set; }
|
||||
public NucachePropertyDecompressionLevel DecompressLevel { get; private set; }
|
||||
public string MappedAlias { get; private set; }
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is NuCacheCompressionOptions options && Equals(options);
|
||||
}
|
||||
|
||||
public bool Equals(NuCacheCompressionOptions other)
|
||||
{
|
||||
return CompressLevel == other.CompressLevel &&
|
||||
DecompressLevel == other.DecompressLevel &&
|
||||
MappedAlias == other.MappedAlias;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
var hashCode = 961370163;
|
||||
hashCode = hashCode * -1521134295 + CompressLevel.GetHashCode();
|
||||
hashCode = hashCode * -1521134295 + DecompressLevel.GetHashCode();
|
||||
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(MappedAlias);
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
public static bool operator ==(NuCacheCompressionOptions left, NuCacheCompressionOptions right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(NuCacheCompressionOptions left, NuCacheCompressionOptions right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
{
|
||||
|
||||
public class NuCachePropertyOptions
|
||||
{
|
||||
public IReadOnlyDictionary<string, (NucachePropertyCompressionLevel compress, NucachePropertyDecompressionLevel decompressionLevel,
|
||||
string mappedAlias)> PropertyMap
|
||||
{ get; set; } = new Dictionary<string, (NucachePropertyCompressionLevel compress,
|
||||
NucachePropertyDecompressionLevel decompressionLevel, string mappedAlias)>();
|
||||
public IReadOnlyDictionary<string, NuCacheCompressionOptions> PropertyMap { get; set; } = new Dictionary<string, NuCacheCompressionOptions>();
|
||||
|
||||
public K4os.Compression.LZ4.LZ4Level LZ4CompressionLevel { get; set; } = K4os.Compression.LZ4.LZ4Level.L00_FAST;
|
||||
|
||||
|
||||
@@ -259,6 +259,7 @@
|
||||
<Compile Include="PublishedCache\NuCache\DataSource\LazyCompressedString.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\DataSource\MsgPackContentNestedDataSerializer.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\DataSource\Lz4DictionaryOfPropertyDataSerializer.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\DataSource\NuCacheCompressionOptions.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\DataSource\NuCachePropertyOptions.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\PublishedSnapshotServiceOptions.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\Snap\GenObj.cs" />
|
||||
|
||||
Reference in New Issue
Block a user