fixes U4-11195 Mapping complex properties slow down some queries

This commit is contained in:
Claus
2018-04-09 15:43:17 +02:00
parent 07fc6753f5
commit 5380b62504
8 changed files with 78 additions and 51 deletions

View File

@@ -195,7 +195,7 @@ namespace Umbraco.Web.Models.Mapping
{
var parent = _contentService.Value.GetById(source.ParentId);
path = parent == null ? "-1" : parent.Path;
}
}
var permissions = svc.GetPermissionsForPath(
//TODO: This is certainly not ideal usage here - perhaps the best way to deal with this in the future is

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Logging;
@@ -13,11 +14,13 @@ namespace Umbraco.Web.Models.Mapping
/// Creates a base generic ContentPropertyBasic from a Property
/// </summary>
/// <typeparam name="T"></typeparam>
internal class ContentPropertyBasicConverter<T> : TypeConverter<Property, T>
internal class ContentPropertyBasicConverter<T> : ITypeConverter<Property, T>
where T : ContentPropertyBasic, new()
{
protected IDataTypeService DataTypeService { get; private set; }
private static readonly List<string> ComplexPropertyTypeAliases = new List<string> {"Umbraco.NestedContent"};
public ContentPropertyBasicConverter(IDataTypeService dataTypeService)
{
DataTypeService = dataTypeService;
@@ -26,28 +29,45 @@ namespace Umbraco.Web.Models.Mapping
/// <summary>
/// Assigns the PropertyEditor, Id, Alias and Value to the property
/// </summary>
/// <param name="property"></param>
/// <returns></returns>
protected override T ConvertCore(Property property)
public T Convert(ResolutionContext context)
{
var property = context.SourceValue as Property;
if (property == null)
throw new InvalidOperationException("Source value is not a property.");
var editor = PropertyEditorResolver.Current.GetByAlias(property.PropertyType.PropertyEditorAlias);
if (editor == null)
{
LogHelper.Error<ContentPropertyBasicConverter<T>>(
"No property editor found, converting to a Label",
new NullReferenceException("The property editor with alias " + property.PropertyType.PropertyEditorAlias + " does not exist"));
new NullReferenceException("The property editor with alias " +
property.PropertyType.PropertyEditorAlias + " does not exist"));
editor = PropertyEditorResolver.Current.GetByAlias(Constants.PropertyEditors.NoEditAlias);
}
var result = new T
{
Id = property.Id,
Value = editor.ValueEditor.ConvertDbToEditor(property, property.PropertyType, DataTypeService),
Alias = property.Alias,
PropertyEditor = editor,
Editor = editor.Alias
};
var result = new T
{
Id = property.Id,
Alias = property.Alias,
PropertyEditor = editor,
Editor = editor.Alias
};
// Complex properties such as Nested Content do not need to be mapped for simpler things like list views,
// where they will not make sense to use anyways. To avoid having to do unnecessary mapping on large
// collections of items in list views - we allow excluding mapping of certain properties.
var excludeComplexProperties = false;
if (context.Options.Items.ContainsKey("ExcludeComplexProperties"))
{
excludeComplexProperties = System.Convert.ToBoolean(context.Options.Items["ExcludeComplexProperties"]);
}
if (excludeComplexProperties == false || ComplexPropertyTypeAliases.Contains(property.PropertyType.PropertyEditorAlias) == false)
{
result.Value = editor.ValueEditor.ConvertDbToEditor(property, property.PropertyType, DataTypeService);
}
return result;
}
}

View File

@@ -1,7 +1,5 @@
using System;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using AutoMapper;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Web.Models.ContentEditing;
@@ -21,27 +19,31 @@ namespace Umbraco.Web.Models.Mapping
_textService = textService;
}
protected override ContentPropertyDisplay ConvertCore(Property originalProp)
public new ContentPropertyDisplay Convert(ResolutionContext context)
{
var display = base.ConvertCore(originalProp);
var display = base.Convert(context);
var originalProperty = context.SourceValue as Property;
if (originalProperty == null)
throw new InvalidOperationException("Source value is not a property.");
var dataTypeService = DataTypeService;
var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(originalProp.PropertyType.DataTypeDefinitionId);
var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(originalProperty.PropertyType.DataTypeDefinitionId);
//configure the editor for display with the pre-values
var valEditor = display.PropertyEditor.ValueEditor;
valEditor.ConfigureForDisplay(preVals);
//set the display properties after mapping
display.Alias = originalProp.Alias;
display.Description = originalProp.PropertyType.Description;
display.Label = originalProp.PropertyType.Name;
display.Alias = originalProperty.Alias;
display.Description = originalProperty.PropertyType.Description;
display.Label = originalProperty.PropertyType.Name;
display.HideLabel = valEditor.HideLabel;
//add the validation information
display.Validation.Mandatory = originalProp.PropertyType.Mandatory;
display.Validation.Pattern = originalProp.PropertyType.ValidationRegExp;
display.Validation.Mandatory = originalProperty.PropertyType.Mandatory;
display.Validation.Pattern = originalProperty.PropertyType.ValidationRegExp;
if (display.PropertyEditor == null)
{
//display.Config = PreValueCollection.AsDictionary(preVals);

View File

@@ -1,7 +1,6 @@
using System;
using Umbraco.Core;
using AutoMapper;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Web.Models.ContentEditing;
@@ -17,9 +16,13 @@ namespace Umbraco.Web.Models.Mapping
{
}
protected override ContentPropertyDto ConvertCore(Property originalProperty)
public new ContentPropertyDto Convert(ResolutionContext context)
{
var propertyDto = base.ConvertCore(originalProperty);
var propertyDto = base.Convert(context);
var originalProperty = context.SourceValue as Property;
if (originalProperty == null)
throw new InvalidOperationException("Source value is not a property.");
var dataTypeService = DataTypeService;
@@ -27,7 +30,7 @@ namespace Umbraco.Web.Models.Mapping
propertyDto.ValidationRegExp = originalProperty.PropertyType.ValidationRegExp;
propertyDto.Description = originalProperty.PropertyType.Description;
propertyDto.Label = originalProperty.PropertyType.Name;
//TODO: We should be able to look both of these up at the same time!
propertyDto.DataType = dataTypeService.GetDataTypeDefinitionById(originalProperty.PropertyType.DataTypeDefinitionId);
propertyDto.PreValues = dataTypeService.GetPreValuesCollectionByDataTypeId(originalProperty.PropertyType.DataTypeDefinitionId);

View File

@@ -1,9 +1,7 @@
using System;
using AutoMapper;
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Mapping;
using Umbraco.Core.Services;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping