From int languageId to string culture

This commit is contained in:
Stephan
2018-04-21 09:57:28 +02:00
parent 5d1abaa713
commit a69019aea0
64 changed files with 708 additions and 626 deletions

View File

@@ -159,7 +159,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
pdatas.Add(pdata);
var type = PrimitiveSerializer.Char.ReadFrom(stream);
pdata.LanguageId = (int?) ReadObject(type, stream);
pdata.Culture = (string) ReadObject(type, stream);
type = PrimitiveSerializer.Char.ReadFrom(stream);
pdata.Segment = (string) ReadObject(type, stream);
type = PrimitiveSerializer.Char.ReadFrom(stream);
@@ -211,7 +211,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
// write each value
foreach (var pdata in kvp.Value)
{
WriteObject(pdata.LanguageId, stream);
WriteObject(pdata.Culture, stream);
WriteObject(pdata.Segment, stream);
WriteObject(pdata.Value, stream);
}

View File

@@ -4,8 +4,8 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
{
internal class PropertyData
{
[JsonProperty("lang")]
public int? LanguageId { get; set; }
[JsonProperty("culture")]
public string Culture { get; set; }
[JsonProperty("seg")]
public string Segment { get; set; }
@@ -13,4 +13,4 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
[JsonProperty("val")]
public object Value { get; set; }
}
}
}

View File

@@ -28,7 +28,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
private object _interValue;
// the variant source and inter values
private Dictionary<CompositeIntStringKey, SourceInterValue> _sourceValues;
private Dictionary<CompositeStringStringKey, SourceInterValue> _sourceValues;
// the variant and non-variant object values
private CacheValues _cacheValues;
@@ -49,16 +49,16 @@ namespace Umbraco.Web.PublishedCache.NuCache
{
foreach (var sourceValue in sourceValues)
{
if (sourceValue.LanguageId == null && sourceValue.Segment == null)
if (sourceValue.Culture == null && sourceValue.Segment == null)
{
_sourceValue = sourceValue.Value;
}
else
{
if (_sourceValues == null)
_sourceValues = new Dictionary<CompositeIntStringKey, SourceInterValue>();
_sourceValues[new CompositeIntStringKey(sourceValue.LanguageId, sourceValue.Segment)]
= new SourceInterValue { LanguageId = sourceValue.LanguageId, Segment = sourceValue.Segment, SourceValue = sourceValue.Value };
_sourceValues = new Dictionary<CompositeStringStringKey, SourceInterValue>();
_sourceValues[new CompositeStringStringKey(sourceValue.Culture, sourceValue.Segment)]
= new SourceInterValue { Culture = sourceValue.Culture, Segment = sourceValue.Segment, SourceValue = sourceValue.Value };
}
}
}
@@ -84,7 +84,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
_publishedSnapshotAccessor = origin._publishedSnapshotAccessor;
}
public override bool HasValue(int? languageId = null, string segment = null) => _sourceValue != null
public override bool HasValue(string culture = null, string segment = null) => _sourceValue != null
&& (!(_sourceValue is string) || string.IsNullOrWhiteSpace((string) _sourceValue) == false);
// used to cache the recursive *property* for this property
@@ -143,9 +143,9 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
// this is always invoked from within a lock, so does not require its own lock
private object GetInterValue(int? languageId, string segment)
private object GetInterValue(string culture, string segment)
{
if (languageId == null && segment == null)
if (culture == null && segment == null)
{
if (_interInitialized) return _interValue;
_interValue = PropertyType.ConvertSourceToInter(_content, _sourceValue, _isPreviewing);
@@ -154,11 +154,11 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
if (_sourceValues == null)
_sourceValues = new Dictionary<CompositeIntStringKey, SourceInterValue>();
_sourceValues = new Dictionary<CompositeStringStringKey, SourceInterValue>();
var k = new CompositeIntStringKey(languageId, segment);
var k = new CompositeStringStringKey(culture, segment);
if (!_sourceValues.TryGetValue(k, out var vvalue))
_sourceValues[k] = vvalue = new SourceInterValue { LanguageId = languageId, Segment = segment };
_sourceValues[k] = vvalue = new SourceInterValue { Culture = culture, Segment = segment };
if (vvalue.InterInitialized) return vvalue.InterValue;
vvalue.InterValue = PropertyType.ConvertSourceToInter(_content, vvalue.SourceValue, _isPreviewing);
@@ -166,45 +166,45 @@ namespace Umbraco.Web.PublishedCache.NuCache
return vvalue.InterValue;
}
public override object GetSourceValue(int? languageId = null, string segment = null)
public override object GetSourceValue(string culture = null, string segment = null)
{
if (languageId == null && segment == null)
if (culture == null && segment == null)
return _sourceValue;
lock (_locko)
{
if (_sourceValues == null) return null;
return _sourceValues.TryGetValue(new CompositeIntStringKey(languageId, segment), out var sourceValue) ? sourceValue.SourceValue : null;
return _sourceValues.TryGetValue(new CompositeStringStringKey(culture, segment), out var sourceValue) ? sourceValue.SourceValue : null;
}
}
public override object GetValue(int? languageId = null, string segment = null)
public override object GetValue(string culture = null, string segment = null)
{
lock (_locko)
{
var cacheValues = GetCacheValues(PropertyType.CacheLevel).For(languageId, segment);
var cacheValues = GetCacheValues(PropertyType.CacheLevel).For(culture, segment);
// initial reference cache level always is .Content
const PropertyCacheLevel initialCacheLevel = PropertyCacheLevel.Element;
if (cacheValues.ObjectInitialized) return cacheValues.ObjectValue;
cacheValues.ObjectValue = PropertyType.ConvertInterToObject(_content, initialCacheLevel, GetInterValue(languageId, segment), _isPreviewing);
cacheValues.ObjectValue = PropertyType.ConvertInterToObject(_content, initialCacheLevel, GetInterValue(culture, segment), _isPreviewing);
cacheValues.ObjectInitialized = true;
return cacheValues.ObjectValue;
}
}
public override object GetXPathValue(int? languageId = null, string segment = null)
public override object GetXPathValue(string culture = null, string segment = null)
{
lock (_locko)
{
var cacheValues = GetCacheValues(PropertyType.CacheLevel).For(languageId, segment);
var cacheValues = GetCacheValues(PropertyType.CacheLevel).For(culture, segment);
// initial reference cache level always is .Content
const PropertyCacheLevel initialCacheLevel = PropertyCacheLevel.Element;
if (cacheValues.XPathInitialized) return cacheValues.XPathValue;
cacheValues.XPathValue = PropertyType.ConvertInterToXPath(_content, initialCacheLevel, GetInterValue(languageId, segment), _isPreviewing);
cacheValues.XPathValue = PropertyType.ConvertInterToXPath(_content, initialCacheLevel, GetInterValue(culture, segment), _isPreviewing);
cacheValues.XPathInitialized = true;
return cacheValues.XPathValue;
}
@@ -222,18 +222,18 @@ namespace Umbraco.Web.PublishedCache.NuCache
private class CacheValues : CacheValue
{
private Dictionary<CompositeIntStringKey, CacheValue> _values;
private Dictionary<CompositeStringStringKey, CacheValue> _values;
// this is always invoked from within a lock, so does not require its own lock
public CacheValue For(int? languageId, string segment)
public CacheValue For(string culture, string segment)
{
if (languageId == null && segment == null)
if (culture == null && segment == null)
return this;
if (_values == null)
_values = new Dictionary<CompositeIntStringKey, CacheValue>();
_values = new Dictionary<CompositeStringStringKey, CacheValue>();
var k = new CompositeIntStringKey(languageId, segment);
var k = new CompositeStringStringKey(culture, segment);
if (!_values.TryGetValue(k, out var value))
_values[k] = value = new CacheValue();
@@ -243,9 +243,14 @@ namespace Umbraco.Web.PublishedCache.NuCache
private class SourceInterValue
{
private string _culture;
private string _segment;
public int? LanguageId { get; set; }
public string Culture
{
get => _culture;
internal set => _culture = value?.ToLowerInvariant();
}
public string Segment
{
get => _segment;

View File

@@ -1183,7 +1183,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
{
var value = published ? pvalue.PublishedValue : pvalue.EditedValue;
if (value != null)
pdatas.Add(new PropertyData { LanguageId = pvalue.LanguageId, Segment = pvalue.Segment, Value = value });
pdatas.Add(new PropertyData { Culture = pvalue.Culture, Segment = pvalue.Segment, Value = value });
//Core.Composing.Current.Logger.Debug<PublishedSnapshotService>($"{content.Id} {prop.Alias} [{pvalue.LanguageId},{pvalue.Segment}] {value} {(published?"pub":"edit")}");

View File

@@ -36,7 +36,7 @@ namespace Umbraco.Web.PublishedCache
IsMember = propertyType.ContentType.ItemType == PublishedItemType.Member;
}
public override bool HasValue(int? languageId = null, string segment = null)
public override bool HasValue(string culture = null, string segment = null)
=> _sourceValue != null && (!(_sourceValue is string s) || !string.IsNullOrWhiteSpace(s));
// used to cache the CacheValues of this property
@@ -136,9 +136,9 @@ namespace Umbraco.Web.PublishedCache
return _interValue;
}
public override object GetSourceValue(int? languageId = null, string segment = null) => _sourceValue;
public override object GetSourceValue(string culture = null, string segment = null) => _sourceValue;
public override object GetValue(int? languageId = null, string segment = null)
public override object GetValue(string culture = null, string segment = null)
{
GetCacheLevels(out var cacheLevel, out var referenceCacheLevel);
@@ -152,7 +152,7 @@ namespace Umbraco.Web.PublishedCache
}
}
public override object GetXPathValue(int? languageId = null, string segment = null)
public override object GetXPathValue(string culture = null, string segment = null)
{
GetCacheLevels(out var cacheLevel, out var referenceCacheLevel);

View File

@@ -27,13 +27,13 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
/// <summary>
/// Gets the raw value of the property.
/// </summary>
public override object GetSourceValue(int? languageId = null, string segment = null) => _sourceValue;
public override object GetSourceValue(string culture = null, string segment = null) => _sourceValue;
// in the Xml cache, everything is a string, and to have a value
// you want to have a non-null, non-empty string.
public override bool HasValue(int? languageId = null, string segment = null) => _sourceValue.Trim().Length > 0;
public override bool HasValue(string culture = null, string segment = null) => _sourceValue.Trim().Length > 0;
public override object GetValue(int? languageId = null, string segment = null)
public override object GetValue(string culture = null, string segment = null)
{
// NOT caching the source (intermediate) value since we'll never need it
// everything in Xml cache is per-request anyways
@@ -48,7 +48,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
return _objectValue;
}
public override object GetXPathValue(int? languageId = null, string segment = null) { throw new NotImplementedException(); }
public override object GetXPathValue(string culture = null, string segment = null) { throw new NotImplementedException(); }
public XmlPublishedProperty(PublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing, XmlNode propertyXmlData)
: this(propertyType, content, isPreviewing)