From a9045c254eda37a296f29e1c834cf1f703385b58 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 7 Feb 2019 14:01:00 +1100 Subject: [PATCH] Removes the need to do any lookup for GetNonGroupedProperties, we already know if they belong to a non-group based on the ID --- src/Umbraco.Core/ContentExtensions.cs | 9 +++------ src/Umbraco.Tests/Models/ContentTests.cs | 4 +--- .../Mapping/MemberTabsAndPropertiesResolver.cs | 4 ++-- .../Models/Mapping/TabsAndPropertiesResolver.cs | 14 ++++++-------- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/Umbraco.Core/ContentExtensions.cs b/src/Umbraco.Core/ContentExtensions.cs index d552b3f960..f802c2d0d9 100644 --- a/src/Umbraco.Core/ContentExtensions.cs +++ b/src/Umbraco.Core/ContentExtensions.cs @@ -106,15 +106,12 @@ namespace Umbraco.Core /// Returns properties that do not belong to a group /// /// - /// /// - public static IEnumerable GetNonGroupedProperties(this IContentBase content, IContentTypeBaseServiceProvider contentTypeBaseService) + public static IEnumerable GetNonGroupedProperties(this IContentBase content) { - var contentType = contentTypeBaseService.GetContentTypeOf(content); - var propertyIdsInTabs = contentType.PropertyGroups.SelectMany(pg => pg.PropertyTypes); return content.Properties - .Where(property => propertyIdsInTabs.Contains(property.PropertyType) == false) - .OrderBy(x => x.PropertyType.SortOrder); + .Where(x => x.PropertyType.PropertyGroupId == null) + .OrderBy(x => x.PropertyType.SortOrder); } /// diff --git a/src/Umbraco.Tests/Models/ContentTests.cs b/src/Umbraco.Tests/Models/ContentTests.cs index f211e570e9..693f919b7a 100644 --- a/src/Umbraco.Tests/Models/ContentTests.cs +++ b/src/Umbraco.Tests/Models/ContentTests.cs @@ -138,9 +138,7 @@ namespace Umbraco.Tests.Models var content = MockedContent.CreateSimpleContent(contentType); //need to id the p - var serviceProvider = new ContentTypeBaseServiceProvider(_contentTypeService, Mock.Of(), Mock.Of()); - - var nonGrouped = content.GetNonGroupedProperties(serviceProvider); + var nonGrouped = content.GetNonGroupedProperties(); Assert.AreEqual(2, nonGrouped.Count()); Assert.AreEqual(5, content.Properties.Count()); diff --git a/src/Umbraco.Web/Models/Mapping/MemberTabsAndPropertiesResolver.cs b/src/Umbraco.Web/Models/Mapping/MemberTabsAndPropertiesResolver.cs index 288b835318..517889277c 100644 --- a/src/Umbraco.Web/Models/Mapping/MemberTabsAndPropertiesResolver.cs +++ b/src/Umbraco.Web/Models/Mapping/MemberTabsAndPropertiesResolver.cs @@ -29,8 +29,8 @@ namespace Umbraco.Web.Models.Mapping private readonly IMemberService _memberService; private readonly IUserService _userService; - public MemberTabsAndPropertiesResolver(IUmbracoContextAccessor umbracoContextAccessor, ILocalizedTextService localizedTextService, IMemberService memberService, IUserService userService, IMemberTypeService memberTypeService, IContentTypeBaseServiceProvider contentTypeServiceProvider) - : base(localizedTextService, contentTypeServiceProvider) + public MemberTabsAndPropertiesResolver(IUmbracoContextAccessor umbracoContextAccessor, ILocalizedTextService localizedTextService, IMemberService memberService, IUserService userService, IMemberTypeService memberTypeService) + : base(localizedTextService) { _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); _localizedTextService = localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService)); diff --git a/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesResolver.cs b/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesResolver.cs index 6f3815f678..dc3cc9e74f 100644 --- a/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesResolver.cs +++ b/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesResolver.cs @@ -12,19 +12,17 @@ namespace Umbraco.Web.Models.Mapping { internal abstract class TabsAndPropertiesResolver { - private readonly IContentTypeBaseServiceProvider _contentTypeServiceProvider; protected ILocalizedTextService LocalizedTextService { get; } protected IEnumerable IgnoreProperties { get; set; } - protected TabsAndPropertiesResolver(ILocalizedTextService localizedTextService, IContentTypeBaseServiceProvider contentTypeServiceProvider) + protected TabsAndPropertiesResolver(ILocalizedTextService localizedTextService) { - _contentTypeServiceProvider = contentTypeServiceProvider; LocalizedTextService = localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService)); IgnoreProperties = new List(); } - protected TabsAndPropertiesResolver(ILocalizedTextService localizedTextService, IContentTypeBaseServiceProvider contentTypeServiceProvider, IEnumerable ignoreProperties) - : this(localizedTextService, contentTypeServiceProvider) + protected TabsAndPropertiesResolver(ILocalizedTextService localizedTextService, IEnumerable ignoreProperties) + : this(localizedTextService) { IgnoreProperties = ignoreProperties ?? throw new ArgumentNullException(nameof(ignoreProperties)); } @@ -52,7 +50,7 @@ namespace Umbraco.Web.Models.Mapping { // add the generic properties tab, for properties that don't belong to a tab // get the properties, map and translate them, then add the tab - var noGroupProperties = content.GetNonGroupedProperties(_contentTypeServiceProvider) + var noGroupProperties = content.GetNonGroupedProperties() .Where(x => IgnoreProperties.Contains(x.Alias) == false) // skip ignored .ToList(); var genericproperties = MapProperties(content, noGroupProperties, context); @@ -124,8 +122,8 @@ namespace Umbraco.Web.Models.Mapping internal class TabsAndPropertiesResolver : TabsAndPropertiesResolver, IValueResolver>> where TSource : IContentBase { - public TabsAndPropertiesResolver(ILocalizedTextService localizedTextService, IContentTypeBaseServiceProvider contentTypeServiceProvider) - : base(localizedTextService, contentTypeServiceProvider) + public TabsAndPropertiesResolver(ILocalizedTextService localizedTextService) + : base(localizedTextService) { } public virtual IEnumerable> Resolve(TSource source, TDestination destination, IEnumerable> destMember, ResolutionContext context)