Merge remote-tracking branch 'origin/v8/dev' into netcore/dev
# Conflicts: # src/SolutionInfo.cs # src/Umbraco.Web.UI/Umbraco/Views/Preview/Index.cshtml # src/Umbraco.Web.UI/config/umbracoSettings.config # src/Umbraco.Web/Services/IconService.cs
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Examine;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Persistence;
|
||||
@@ -14,7 +13,7 @@ namespace Umbraco.Examine
|
||||
/// <summary>
|
||||
/// Performs the data lookups required to rebuild a content index
|
||||
/// </summary>
|
||||
public class ContentIndexPopulator : IndexPopulator<IUmbracoContentIndex>
|
||||
public class ContentIndexPopulator : IndexPopulator<IUmbracoContentIndex2>
|
||||
{
|
||||
private readonly IContentService _contentService;
|
||||
private readonly IValueSetBuilder<IContent> _contentValueSetBuilder;
|
||||
@@ -57,6 +56,12 @@ namespace Umbraco.Examine
|
||||
_parentId = parentId;
|
||||
}
|
||||
|
||||
public override bool IsRegistered(IUmbracoContentIndex2 index)
|
||||
{
|
||||
// check if it should populate based on published values
|
||||
return _publishedValuesOnly == index.PublishedValuesOnly;
|
||||
}
|
||||
|
||||
protected override void PopulateIndexes(IReadOnlyList<IIndex> indexes)
|
||||
{
|
||||
if (indexes.Count == 0) return;
|
||||
@@ -69,31 +74,89 @@ namespace Umbraco.Examine
|
||||
{
|
||||
contentParentId = _parentId.Value;
|
||||
}
|
||||
|
||||
if (_publishedValuesOnly)
|
||||
{
|
||||
IndexPublishedContent(contentParentId, pageIndex, pageSize, indexes);
|
||||
}
|
||||
else
|
||||
{
|
||||
IndexAllContent(contentParentId, pageIndex, pageSize, indexes);
|
||||
}
|
||||
}
|
||||
|
||||
protected void IndexAllContent(int contentParentId, int pageIndex, int pageSize, IReadOnlyList<IIndex> indexes)
|
||||
{
|
||||
IContent[] content;
|
||||
|
||||
do
|
||||
{
|
||||
if (!_publishedValuesOnly)
|
||||
{
|
||||
content = _contentService.GetPagedDescendants(contentParentId, pageIndex, pageSize, out _).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
//add the published filter
|
||||
//note: We will filter for published variants in the validator
|
||||
content = _contentService.GetPagedDescendants(contentParentId, pageIndex, pageSize, out _,
|
||||
_publishedQuery, Ordering.By("Path", Direction.Ascending)).ToArray();
|
||||
}
|
||||
content = _contentService.GetPagedDescendants(contentParentId, pageIndex, pageSize, out _).ToArray();
|
||||
|
||||
if (content.Length > 0)
|
||||
{
|
||||
var valueSets = _contentValueSetBuilder.GetValueSets(content).ToList();
|
||||
|
||||
// ReSharper disable once PossibleMultipleEnumeration
|
||||
foreach (var index in indexes)
|
||||
index.IndexItems(_contentValueSetBuilder.GetValueSets(content));
|
||||
{
|
||||
index.IndexItems(valueSets);
|
||||
}
|
||||
}
|
||||
|
||||
pageIndex++;
|
||||
} while (content.Length == pageSize);
|
||||
}
|
||||
|
||||
protected void IndexPublishedContent(int contentParentId, int pageIndex, int pageSize,
|
||||
IReadOnlyList<IIndex> indexes)
|
||||
{
|
||||
IContent[] content;
|
||||
|
||||
var publishedPages = new HashSet<int>();
|
||||
|
||||
do
|
||||
{
|
||||
//add the published filter
|
||||
//note: We will filter for published variants in the validator
|
||||
content = _contentService.GetPagedDescendants(contentParentId, pageIndex, pageSize, out _, _publishedQuery,
|
||||
Ordering.By("Path", Direction.Ascending)).ToArray();
|
||||
|
||||
|
||||
if (content.Length > 0)
|
||||
{
|
||||
var indexableContent = new List<IContent>();
|
||||
|
||||
foreach (var item in content)
|
||||
{
|
||||
if (item.Level == 1)
|
||||
{
|
||||
// first level pages are always published so no need to filter them
|
||||
indexableContent.Add(item);
|
||||
publishedPages.Add(item.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (publishedPages.Contains(item.ParentId))
|
||||
{
|
||||
// only index when parent is published
|
||||
publishedPages.Add(item.Id);
|
||||
indexableContent.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var valueSets = _contentValueSetBuilder.GetValueSets(indexableContent.ToArray()).ToList();
|
||||
|
||||
// ReSharper disable once PossibleMultipleEnumeration
|
||||
foreach (var index in indexes)
|
||||
index.IndexItems(valueSets);
|
||||
}
|
||||
|
||||
pageIndex++;
|
||||
} while (content.Length == pageSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,20 @@ using Examine;
|
||||
|
||||
namespace Umbraco.Examine
|
||||
{
|
||||
/// <summary>
|
||||
/// Marker interface for indexes of Umbraco content
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is a backwards compat change, in next major version remove the need for this and just have a single interface
|
||||
/// </remarks>
|
||||
public interface IUmbracoContentIndex2 : IUmbracoContentIndex
|
||||
{
|
||||
bool PublishedValuesOnly { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marker interface for indexes of Umbraco content
|
||||
/// </summary>
|
||||
public interface IUmbracoContentIndex : IIndex
|
||||
{
|
||||
|
||||
|
||||
@@ -13,9 +13,16 @@ namespace Umbraco.Examine
|
||||
{
|
||||
public override bool IsRegistered(IIndex index)
|
||||
{
|
||||
if (base.IsRegistered(index)) return true;
|
||||
return index is TIndex;
|
||||
if (base.IsRegistered(index))
|
||||
return true;
|
||||
|
||||
if (!(index is TIndex casted))
|
||||
return false;
|
||||
|
||||
return IsRegistered(casted);
|
||||
}
|
||||
|
||||
public virtual bool IsRegistered(TIndex index) => true;
|
||||
}
|
||||
|
||||
public abstract class IndexPopulator : IIndexPopulator
|
||||
|
||||
Reference in New Issue
Block a user