diff --git a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/ContentSerializedData.cs b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/ContentNestedData.cs
similarity index 91%
rename from src/Umbraco.Web/PublishedCache/NuCache/DataSource/ContentSerializedData.cs
rename to src/Umbraco.Web/PublishedCache/NuCache/DataSource/ContentNestedData.cs
index b2cb22a74b..be3e813275 100644
--- a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/ContentSerializedData.cs
+++ b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/ContentNestedData.cs
@@ -6,7 +6,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
///
/// The content item 1:M data that is serialized to JSON
///
- internal class ContentSerializedData
+ internal class ContentNestedData
{
[JsonProperty("properties")]
public Dictionary PropertyData { get; set; }
diff --git a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/Database.cs b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/Database.cs
index 2c4249cd08..342ad5b59f 100644
--- a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/Database.cs
+++ b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/Database.cs
@@ -190,7 +190,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
}
else
{
- var deserialized = DeserializeData(dto.EditData);
+ var nested = DeserializeNestedData(dto.EditData);
d = new ContentData
{
@@ -200,8 +200,8 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
VersionId = dto.VersionId,
VersionDate = dto.EditVersionDate,
WriterId = dto.EditWriterId,
- Properties = deserialized.PropertyData,
- CultureInfos = deserialized.CultureData
+ Properties = nested.PropertyData,
+ CultureInfos = nested.CultureData
};
}
@@ -215,7 +215,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
}
else
{
- var deserialized = DeserializeData(dto.PubData);
+ var nested = DeserializeNestedData(dto.PubData);
p = new ContentData
{
@@ -225,8 +225,8 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
VersionId = dto.VersionId,
VersionDate = dto.PubVersionDate,
WriterId = dto.PubWriterId,
- Properties = deserialized.PropertyData,
- CultureInfos = deserialized.CultureData
+ Properties = nested.PropertyData,
+ CultureInfos = nested.CultureData
};
}
}
@@ -250,7 +250,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
if (dto.EditData == null)
throw new Exception("No data for media " + dto.Id);
- var deserialized = DeserializeData(dto.EditData);
+ var nested = DeserializeNestedData(dto.EditData);
var p = new ContentData
{
@@ -260,8 +260,8 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
VersionId = dto.VersionId,
VersionDate = dto.EditVersionDate,
WriterId = dto.CreatorId, // what-else?
- Properties = deserialized.PropertyData,
- CultureInfos = deserialized.CultureData
+ Properties = nested.PropertyData,
+ CultureInfos = nested.CultureData
};
var n = new ContentNode(dto.Id, dto.Uid,
@@ -277,7 +277,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
return s;
}
- private static ContentSerializedData DeserializeData(string data)
+ private static ContentNestedData DeserializeNestedData(string data)
{
// by default JsonConvert will deserialize our numeric values as Int64
// which is bad, because they were Int32 in the database - take care
@@ -287,7 +287,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
Converters = new List { new ForceInt32Converter() }
};
- return JsonConvert.DeserializeObject(data, settings);
+ return JsonConvert.DeserializeObject(data, settings);
}
}
}
diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs
index 4502245c5a..883a43a7d5 100644
--- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs
+++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs
@@ -35,15 +35,10 @@ namespace Umbraco.Web.PublishedCache.NuCache
var properties = new List();
foreach (var propertyType in _contentNode.ContentType.PropertyTypes)
{
- if (contentData.Properties.TryGetValue(propertyType.Alias, out var pdatas))
- {
- properties.Add(new Property(propertyType, this, pdatas, _publishedSnapshotAccessor));
- }
- else
- {
- //it doesn't exist in our serialized json but we should add it as an empty property so they are in sync
- properties.Add(new Property(propertyType, this, null, _publishedSnapshotAccessor));
- }
+ // add one property per property type - this is required, for the indexing to work
+ // if contentData supplies pdatas, use them, else use null
+ contentData.Properties.TryGetValue(propertyType.Alias, out var pdatas); // else will be null
+ properties.Add(new Property(propertyType, this, pdatas, _publishedSnapshotAccessor));
}
PropertiesArray = properties.ToArray();
}
@@ -265,9 +260,9 @@ namespace Umbraco.Web.PublishedCache.NuCache
public override IPublishedProperty GetProperty(string alias)
{
var index = _contentNode.ContentType.GetPropertyIndex(alias);
- if (index < 0) return null;
- //fixme: This should not happen since we align the PropertiesArray with the property types in the ctor, if this does happen maybe we should throw a descriptive exception
- if (index >= PropertiesArray.Length) return null;
+ if (index < 0) return null; // happens when 'alias' does not match a content type property alias
+ if (index >= PropertiesArray.Length) // should never happen - properties array must be in sync with property type
+ throw new IndexOutOfRangeException("Index points outside the properties array, which means the properties array is corrupt.");
var property = PropertiesArray[index];
return property;
}
diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs
index eae0fd50b5..faff5e9793 100644
--- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs
+++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs
@@ -1179,9 +1179,6 @@ namespace Umbraco.Web.PublishedCache.NuCache
//var propertyEditorResolver = PropertyEditorResolver.Current;
//var dataTypeService = ApplicationContext.Current.Services.DataTypeService;
- //the dictionary that will be serialized
- var data = new ContentSerializedData();
-
var propertyData = new Dictionary();
foreach (var prop in content.Properties)
{
@@ -1216,8 +1213,6 @@ namespace Umbraco.Web.PublishedCache.NuCache
propertyData[prop.Alias] = pdatas.ToArray();
}
- data.PropertyData = propertyData;
-
var cultureData = new Dictionary();
if (content.Names != null)
{
@@ -1233,7 +1228,12 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
}
- data.CultureData = cultureData;
+ //the dictionary that will be serialized
+ var nestedData = new ContentNestedData
+ {
+ PropertyData = propertyData,
+ CultureData = cultureData
+ };
var dto = new ContentNuDto
{
@@ -1243,7 +1243,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
// note that numeric values (which are Int32) are serialized without their
// type (eg "value":1234) and JsonConvert by default deserializes them as Int64
- Data = JsonConvert.SerializeObject(data)
+ Data = JsonConvert.SerializeObject(nestedData)
};
//Core.Composing.Current.Logger.Debug(dto.Data);
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj
index 01e064d398..98afb387d4 100644
--- a/src/Umbraco.Web/Umbraco.Web.csproj
+++ b/src/Umbraco.Web/Umbraco.Web.csproj
@@ -346,7 +346,7 @@
-
+