From d3aa1b3d7e04cbce7032f21b36aef1d6deb4f2e4 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 5 Dec 2013 14:24:26 +1100 Subject: [PATCH] Ensures that the ContentBase item is set on Document/Media and that the property value is set based on the already loaded value in the model if IData implements IDataValueSetter (which DefaultData does). This streamlines how properties get their data and will save on a ton of queries when using the legacy API. --- src/umbraco.cms/businesslogic/Property/Property.cs | 9 +++++++++ src/umbraco.cms/businesslogic/media/Media.cs | 2 ++ src/umbraco.cms/businesslogic/web/Document.cs | 3 +++ 3 files changed, 14 insertions(+) diff --git a/src/umbraco.cms/businesslogic/Property/Property.cs b/src/umbraco.cms/businesslogic/Property/Property.cs index b7450612bd..8adac0d7e3 100644 --- a/src/umbraco.cms/businesslogic/Property/Property.cs +++ b/src/umbraco.cms/businesslogic/Property/Property.cs @@ -8,6 +8,7 @@ using umbraco.DataLayer; using umbraco.BusinessLogic; using umbraco.cms.businesslogic.datatype; using umbraco.cms.businesslogic.propertytype; +using umbraco.interfaces; namespace umbraco.cms.businesslogic.property { @@ -62,6 +63,14 @@ namespace umbraco.cms.businesslogic.property _pt = PropertyType.GetPropertyType(property.PropertyTypeId); _data = _pt.DataTypeDefinition.DataType.Data; _data.PropertyId = Id; + + //set the value so it doesn't need to go to the database + var dvs = _data as IDataValueSetter; + if (dvs != null) + { + dvs.SetValue(property.Value, property.PropertyType.DataTypeDatabaseType.ToString()); + } + } public Guid VersionId diff --git a/src/umbraco.cms/businesslogic/media/Media.cs b/src/umbraco.cms/businesslogic/media/Media.cs index 00ec1efb0b..586bedf75c 100644 --- a/src/umbraco.cms/businesslogic/media/Media.cs +++ b/src/umbraco.cms/businesslogic/media/Media.cs @@ -381,6 +381,8 @@ namespace umbraco.cms.businesslogic.media private void SetupNode(IMedia media) { MediaItem = media; + //Also need to set the ContentBase item to this one so all the propery values load from it + ContentBase = MediaItem; //Setting private properties from IContentBase replacing CMSNode.setupNode() / CMSNode.PopulateCMSNodeFromReader() base.PopulateCMSNodeFromUmbracoEntity(MediaItem, _objectType); diff --git a/src/umbraco.cms/businesslogic/web/Document.cs b/src/umbraco.cms/businesslogic/web/Document.cs index 25482f2f7b..d848667400 100644 --- a/src/umbraco.cms/businesslogic/web/Document.cs +++ b/src/umbraco.cms/businesslogic/web/Document.cs @@ -1423,6 +1423,9 @@ namespace umbraco.cms.businesslogic.web private void SetupNode(IContent content) { Content = content; + //Also need to set the ContentBase item to this one so all the propery values load from it + ContentBase = Content; + //Setting private properties from IContentBase replacing CMSNode.setupNode() / CMSNode.PopulateCMSNodeFromReader() base.PopulateCMSNodeFromUmbracoEntity(Content, _objectType);