Updated the RebuildXmlStructures method with performance improvements. Added cache checking to the GetByPublishedVersion method since published content should always be 'latest' this will speed things up tremendously if items are found there. Added 2 more performance tests which show very large perf improvements, namely the Get_All_Published_Content_Of_Type shows a 77% improvement.

This commit is contained in:
Shannon
2013-07-29 15:49:56 +10:00
parent 696306e7c9
commit b9ba350a2f
4 changed files with 184 additions and 23 deletions

View File

@@ -449,7 +449,15 @@ namespace Umbraco.Core.Persistence.Repositories
foreach (var dto in dtos)
{
yield return CreateContentFromDto(dto, dto.VersionId);
var fromCache = TryGetFromCache(dto.NodeId);
if (fromCache.Success)
{
yield return fromCache.Result;
}
else
{
yield return CreateContentFromDto(dto, dto.VersionId);
}
}
}

View File

@@ -85,11 +85,10 @@ namespace Umbraco.Core.Persistence.Repositories
/// <returns></returns>
public TEntity Get(TId id)
{
Guid key = id is int ? ConvertIdToGuid(id) : ConvertStringIdToGuid(id.ToString());
var rEntity = _cache.GetById(typeof(TEntity), key);
if (rEntity != null)
var fromCache = TryGetFromCache(id);
if (fromCache.Success)
{
return (TEntity)rEntity;
return fromCache.Result;
}
var entity = PerformGet(id);
@@ -112,6 +111,17 @@ namespace Umbraco.Core.Persistence.Repositories
return entity;
}
protected Attempt<TEntity> TryGetFromCache(TId id)
{
Guid key = id is int ? ConvertIdToGuid(id) : ConvertStringIdToGuid(id.ToString());
var rEntity = _cache.GetById(typeof(TEntity), key);
if (rEntity != null)
{
return new Attempt<TEntity>(true, (TEntity) rEntity);
}
return Attempt<TEntity>.False;
}
protected abstract IEnumerable<TEntity> PerformGetAll(params TId[] ids);
/// <summary>
/// Gets all entities of type TEntity or a list according to the passed in Ids
@@ -173,14 +183,12 @@ namespace Umbraco.Core.Persistence.Repositories
/// <returns></returns>
public bool Exists(TId id)
{
Guid key = id is int ? ConvertIdToGuid(id) : ConvertStringIdToGuid(id.ToString());
var rEntity = _cache.GetById(typeof(TEntity), key);
if (rEntity != null)
var fromCache = TryGetFromCache(id);
if (fromCache.Success)
{
return true;
}
return PerformExists(id);
return PerformExists(id);
}
protected abstract int PerformCount(IQuery<TEntity> query);

View File

@@ -13,6 +13,7 @@ using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Caching;
using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Core.Persistence.UnitOfWork;
using Umbraco.Core.Publishing;
@@ -250,6 +251,17 @@ namespace Umbraco.Core.Services
}
}
internal IEnumerable<IContent> GetPublishedContentOfContentType(int id)
{
using (var repository = _repositoryFactory.CreateContentRepository(_uowProvider.GetUnitOfWork()))
{
var query = Query<IContent>.Builder.Where(x => x.ContentTypeId == id);
var contents = repository.GetByPublishedVersion(query);
return contents;
}
}
/// <summary>
/// Gets a collection of <see cref="IContent"/> objects by Level
/// </summary>
@@ -431,6 +443,19 @@ namespace Umbraco.Core.Services
}
}
/// <summary>
/// Gets all published content items
/// </summary>
/// <returns></returns>
internal IEnumerable<IContent> GetAllPublished()
{
using (var repository = _repositoryFactory.CreateContentRepository(_uowProvider.GetUnitOfWork()))
{
var query = Query<IContent>.Builder.Where(x => x.Trashed == false);
return repository.GetByPublishedVersion(query);
}
}
/// <summary>
/// Gets a collection of <see cref="IContent"/> objects, which has an expiration date less than or equal to today.
/// </summary>
@@ -1359,23 +1384,13 @@ namespace Umbraco.Core.Services
uow.Database.Execute(@"DELETE FROM cmsContentXml WHERE nodeId IN
(SELECT DISTINCT cmsContentXml.nodeId FROM cmsContentXml
INNER JOIN cmsDocument ON cmsContentXml.nodeId = cmsDocument.nodeId)");
//get all content items that are published
// Consider creating a Path query instead of recursive method:
// var query = Query<IContent>.Builder.Where(x => x.Path.StartsWith("-1"));
var rootContent = GetRootContent();
foreach (var content in rootContent.Where(content => content.Published))
{
list.Add(content);
list.AddRange(GetPublishedDescendants(content));
}
list.AddRange(GetAllPublished());
}
else
{
foreach (var id in contentTypeIds)
{
//first we'll clear out the data from the cmsContentXml table for this type
uow.Database.Execute(@"delete from cmsContentXml where nodeId in
(select cmsDocument.nodeId from cmsDocument
@@ -1383,7 +1398,7 @@ namespace Umbraco.Core.Services
where published = 1 and contentType = @contentTypeId)", new {contentTypeId = id});
//now get all published content objects of this type and add to the list
list.AddRange(GetContentOfContentType(id).Where(content => content.Published));
list.AddRange(GetPublishedContentOfContentType(id));
}
}