Making a few optimizations based on the findings in v.4.11.4.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
@@ -78,5 +79,35 @@ namespace Umbraco.Tests.Persistence.Querying
|
||||
Assert.That(strResult, Is.EqualTo(expectedResult));
|
||||
Console.WriteLine(strResult);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Build_PublishedDescendants_Query_For_IContent()
|
||||
{
|
||||
// Arrange
|
||||
var path = "-1,1046,1076,1089";
|
||||
var id = 1046;
|
||||
var nodeObjectTypeId = new Guid("C66BA18E-EAF3-4CFF-8A22-41B16D66A972");
|
||||
|
||||
var sql = new Sql();
|
||||
sql.Select("*")
|
||||
.From<DocumentDto>()
|
||||
.InnerJoin<ContentVersionDto>()
|
||||
.On<DocumentDto, ContentVersionDto>(left => left.VersionId, right => right.VersionId)
|
||||
.InnerJoin<ContentDto>()
|
||||
.On<ContentVersionDto, ContentDto>(left => left.NodeId, right => right.NodeId)
|
||||
.InnerJoin<NodeDto>()
|
||||
.On<ContentDto, NodeDto>(left => left.NodeId, right => right.NodeId)
|
||||
.Where<NodeDto>(x => x.NodeObjectType == nodeObjectTypeId);
|
||||
|
||||
var query = Query<IContent>.Builder.Where(x => x.Path.StartsWith(path) && x.Id != id && x.Published == true && x.Trashed == false);
|
||||
|
||||
// Act
|
||||
var translator = new SqlTranslator<IContent>(sql, query);
|
||||
var result = translator.Translate();
|
||||
var strResult = result.SQL;
|
||||
|
||||
// Assert
|
||||
Console.WriteLine(strResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using System.Web.UI.WebControls;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Caching;
|
||||
using Umbraco.Core.Services;
|
||||
using umbraco.BusinessLogic.Actions;
|
||||
using umbraco.IO;
|
||||
using umbraco.uicontrols.DatePicker;
|
||||
@@ -316,6 +317,8 @@ namespace umbraco.cms.presentation
|
||||
{
|
||||
if (_document.Level == 1 || _document.PathPublished)
|
||||
{
|
||||
var previouslyPublished = _document.HasPublishedVersion();
|
||||
|
||||
Trace.Warn("before d.publish");
|
||||
|
||||
if (_document.PublishWithResult(base.getUser()))
|
||||
@@ -330,15 +333,19 @@ namespace umbraco.cms.presentation
|
||||
|
||||
_documentHasPublishedVersion = _document.HasPublishedVersion();
|
||||
|
||||
var descendants = ApplicationContext.Current.Services.ContentService.GetDescendants(_document.Id);
|
||||
var publishableDescendants = descendants.Where(descendant => descendant.HasPublishedVersion()).ToList();
|
||||
if(publishableDescendants.Any())
|
||||
if (previouslyPublished == false)
|
||||
{
|
||||
foreach (var descendant in publishableDescendants)
|
||||
var descendants = ((ContentService) ApplicationContext.Current.Services.ContentService)
|
||||
.GetPublishedDescendants(_document.Content).ToList();
|
||||
|
||||
if (descendants.Any())
|
||||
{
|
||||
library.UpdateDocumentCache(descendant.Id);
|
||||
foreach (var descendant in descendants)
|
||||
{
|
||||
library.UpdateDocumentCache(descendant.Id);
|
||||
}
|
||||
library.RefreshContent();
|
||||
}
|
||||
library.RefreshContent();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user