Slight refactor and cleanup
This commit is contained in:
@@ -140,6 +140,9 @@ namespace Umbraco.Core.Persistence.Factories
|
||||
/// <returns></returns>
|
||||
internal static bool TryMatch(string text, out string mediaPath)
|
||||
{
|
||||
//TODO: In v8 we should allow exposing this via the property editor in a much nicer way so that the property editor
|
||||
// can tell us directly what any URL is for a given property if it contains an asset
|
||||
|
||||
mediaPath = null;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
@@ -155,4 +158,4 @@ namespace Umbraco.Core.Persistence.Factories
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,31 +333,15 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
/// <summary>
|
||||
/// Gets entities by query.
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="objectTypeId"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// Note that this will also fetch all property data for media items, which can cause performance problems
|
||||
/// when used without paging, in sites with large amounts of data in cmsPropertyData.
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="objectTypeId"></param>
|
||||
/// <returns></returns>
|
||||
/// </remarks>
|
||||
public virtual IEnumerable<IUmbracoEntity> GetByQuery(IQuery<IUmbracoEntity> query, Guid objectTypeId)
|
||||
{
|
||||
return GetByQueryInternal(query, objectTypeId, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets entities by query without fetching property data.
|
||||
/// This is supposed to be internal and can be used when getting all entities without paging, without causing
|
||||
/// performance issues.
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="objectTypeId"></param>
|
||||
/// <returns></returns>
|
||||
internal IEnumerable<IUmbracoEntity> GetByQueryWithoutPropertyData(IQuery<IUmbracoEntity> query, Guid objectTypeId)
|
||||
{
|
||||
return GetByQueryInternal(query, objectTypeId, false);
|
||||
}
|
||||
|
||||
internal IEnumerable<IUmbracoEntity> GetByQueryInternal(IQuery<IUmbracoEntity> query, Guid objectTypeId, bool includePropertyData)
|
||||
{
|
||||
var isContent = objectTypeId == Constants.ObjectTypes.DocumentGuid || objectTypeId == Constants.ObjectTypes.DocumentBlueprintGuid;
|
||||
var isMedia = objectTypeId == Constants.ObjectTypes.MediaGuid;
|
||||
@@ -369,11 +353,11 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
var factory = new UmbracoEntityFactory();
|
||||
|
||||
if (isMedia && includePropertyData)
|
||||
if (isMedia)
|
||||
{
|
||||
var wheres = query.GetWhereClauses().ToArray();
|
||||
|
||||
var mediaSql = GetFullSqlForMedia(entitySql.Append(GetGroupBy(isContent, isMedia, false)), sql =>
|
||||
var mediaSql = GetFullSqlForMedia(entitySql.Append(GetGroupBy(isContent, true, false)), sql =>
|
||||
{
|
||||
//adds the additional filters
|
||||
foreach (var whereClause in wheres)
|
||||
@@ -389,20 +373,47 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
}
|
||||
else
|
||||
{
|
||||
//use dynamic so that we can get ALL properties from the SQL so we can chuck that data into our AdditionalData
|
||||
var finalSql = entitySql.Append(GetGroupBy(isContent, isMedia));
|
||||
|
||||
//query = read forward data reader, do not load everything into mem
|
||||
var dtos = _work.Database.Query<dynamic>(finalSql);
|
||||
var collection = new EntityDefinitionCollection();
|
||||
foreach (var dto in dtos)
|
||||
{
|
||||
collection.AddOrUpdate(new EntityDefinition(factory, dto, isContent, isMedia));
|
||||
}
|
||||
return collection.Select(x => x.BuildFromDynamic()).ToList();
|
||||
return GetByQueryInternal(entitySql, isContent, isMedia);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets entities by query without fetching property data.
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="objectTypeId"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// This is supposed to be internal and can be used when getting all entities without paging, without causing
|
||||
/// performance issues.
|
||||
/// </remarks>
|
||||
internal IEnumerable<IUmbracoEntity> GetMediaByQueryWithoutPropertyData(IQuery<IUmbracoEntity> query)
|
||||
{
|
||||
var sqlClause = GetBaseWhere(GetBase, false, true, null, UmbracoObjectTypes.Media.GetGuid());
|
||||
|
||||
var translator = new SqlTranslator<IUmbracoEntity>(sqlClause, query);
|
||||
var entitySql = translator.Translate();
|
||||
|
||||
return GetByQueryInternal(entitySql, false, true);
|
||||
}
|
||||
|
||||
internal IEnumerable<IUmbracoEntity> GetByQueryInternal(Sql entitySql, bool isContent, bool isMedia)
|
||||
{
|
||||
var factory = new UmbracoEntityFactory();
|
||||
|
||||
//use dynamic so that we can get ALL properties from the SQL so we can chuck that data into our AdditionalData
|
||||
var finalSql = entitySql.Append(GetGroupBy(isContent, isMedia));
|
||||
|
||||
//query = read forward data reader, do not load everything into mem
|
||||
var dtos = _work.Database.Query<dynamic>(finalSql);
|
||||
var collection = new EntityDefinitionCollection();
|
||||
foreach (var dto in dtos)
|
||||
{
|
||||
collection.AddOrUpdate(new EntityDefinition(factory, dto, isContent, isMedia));
|
||||
}
|
||||
return collection.Select(x => x.BuildFromDynamic()).ToList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user