From e6d8a835196d66fc3fbc4526a4d199ac0db5a66e Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 5 Dec 2013 14:26:18 +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 8404081677..3fa6284b00 100644 --- a/src/umbraco.cms/businesslogic/Property/Property.cs +++ b/src/umbraco.cms/businesslogic/Property/Property.cs @@ -7,6 +7,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 { @@ -61,6 +62,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 6dcff5792f..805ed1a567 100644 --- a/src/umbraco.cms/businesslogic/media/Media.cs +++ b/src/umbraco.cms/businesslogic/media/Media.cs @@ -380,6 +380,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 c1d27fce58..d330a4e8dd 100644 --- a/src/umbraco.cms/businesslogic/web/Document.cs +++ b/src/umbraco.cms/businesslogic/web/Document.cs @@ -1428,6 +1428,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);