fixes the n+1 queries on content and media type controllers and ensures if there are no ids that the query doesn' texeucte.

This commit is contained in:
Shannon
2014-09-02 11:53:12 +10:00
parent c21dcb0279
commit 03f9b89810
2 changed files with 11 additions and 6 deletions

View File

@@ -59,7 +59,7 @@ namespace Umbraco.Web.Editors
{
types = Services.ContentTypeService.GetAllContentTypes().ToList();
//if no allowed root types are set, just return everythibg
//if no allowed root types are set, just return everything
if(types.Any(x => x.AllowedAsRoot))
types = types.Where(x => x.AllowedAsRoot);
}
@@ -71,9 +71,11 @@ namespace Umbraco.Web.Editors
throw new HttpResponseException(HttpStatusCode.NotFound);
}
types = Services.ContentTypeService.GetAllContentTypes(
contentItem.ContentType.AllowedContentTypes.Select(x => x.Id.Value).ToArray())
.ToList();
var ids = contentItem.ContentType.AllowedContentTypes.Select(x => x.Id.Value).ToArray();
if (ids.Any() == false) return Enumerable.Empty<ContentTypeBasic>();
types = Services.ContentTypeService.GetAllContentTypes(ids).ToList();
}
var basics = types.Select(Mapper.Map<IContentType, ContentTypeBasic>).ToList();

View File

@@ -61,8 +61,11 @@ namespace Umbraco.Web.Editors
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return Services.ContentTypeService.GetAllMediaTypes(
contentItem.ContentType.AllowedContentTypes.Select(x => x.Id.Value).ToArray())
var ids = contentItem.ContentType.AllowedContentTypes.Select(x => x.Id.Value).ToArray();
if (ids.Any() == false) return Enumerable.Empty<ContentTypeBasic>();
return Services.ContentTypeService.GetAllMediaTypes(ids)
.Select(Mapper.Map<IMediaType, ContentTypeBasic>);
}