Making a few optimizations based on the findings in v.4.11.4.

This commit is contained in:
Morten Christensen
2013-01-30 12:11:10 -01:00
parent bd12cb3ae5
commit 0c19307fa3
3 changed files with 67 additions and 11 deletions

View File

@@ -1054,6 +1054,22 @@ namespace Umbraco.Core.Services
return SaveAndPublishDo(content, omitCacheRefresh, userId, raiseEvents);
}
/// <summary>
/// Gets a collection of <see cref="IContent"/> descendants by the first Parent.
/// </summary>
/// <param name="content"><see cref="IContent"/> item to retrieve Descendants from</param>
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
internal IEnumerable<IContent> GetPublishedDescendants(IContent content)
{
using (var repository = _repositoryFactory.CreateContentRepository(_uowProvider.GetUnitOfWork()))
{
var query = Query<IContent>.Builder.Where(x => x.Id != content.Id && x.Path.StartsWith(content.Path) && x.Published == true && x.Trashed == false);
var contents = repository.GetByQuery(query);
return contents;
}
}
#endregion
#region Private Methods
@@ -1243,6 +1259,9 @@ namespace Umbraco.Core.Services
return false;
}
//Has this content item previously been published? If so, we don't need to refresh the children
var previouslyPublished = HasPublishedVersion(content.Id);
//Check if parent is published (although not if its a root node) - if parent isn't published this Content cannot be published
if (content.ParentId != -1 && content.ParentId != -20 && IsPublishable(content) == false)
{
@@ -1294,13 +1313,12 @@ namespace Umbraco.Core.Services
if (omitCacheRefresh == false)
_publishingStrategy.PublishingFinalized(content);
//We need to check if children and their publish state to ensure that we republish content that was previously published
if (omitCacheRefresh == false && HasChildren(content.Id))
//We need to check if children and their publish state to ensure that we 'republish' content that was previously published
if (omitCacheRefresh == false && previouslyPublished == false && HasChildren(content.Id))
{
var children = GetDescendants(content);
var shouldBeRepublished = children.Where(child => HasPublishedVersion(child.Id));
var descendants = GetPublishedDescendants(content);
_publishingStrategy.PublishingFinalized(shouldBeRepublished, false);
_publishingStrategy.PublishingFinalized(descendants, false);
}
Audit.Add(AuditTypes.Publish, "Save and Publish performed by user", userId, content.Id);