U4-9318 Examine indexes inherited unpublished nodes on index RebuildIndex

This reduces allocations since we don't need to create a new serializer for every doc
This commit is contained in:
Shannon
2017-01-03 16:43:54 +11:00
parent d671caf3ab
commit c871a711dd

View File

@@ -32,6 +32,7 @@ namespace UmbracoExamine
private readonly IDataTypeService _dataTypeService;
private readonly IUserService _userService;
private readonly IContentTypeService _contentTypeService;
private readonly EntityXmlSerializer _serializer = new EntityXmlSerializer();
#region Constructors
@@ -142,12 +143,10 @@ namespace UmbracoExamine
_userService = userService;
_contentTypeService = contentTypeService;
}
#endregion
#region Constants & Fields
#region Constants & Fields
/// <summary>
/// Used to store the path of a content object
@@ -382,6 +381,9 @@ namespace UmbracoExamine
}
IContent[] content;
//used to track non-published entities so we can determine what items are implicitly not published
var notPublished = new HashSet<string>();
do
{
long total;
@@ -398,8 +400,9 @@ namespace UmbracoExamine
_publishedQuery = Query<IContent>.Builder.Where(x => x.Published == true);
}
//add the published filter
descendants = _contentService.GetPagedDescendants(contentParentId, pageIndex, pageSize, out total, "Path", Direction.Ascending, true, _publishedQuery);
//get all paged records but order by level ascending, we need to do this because we need to track which nodes are not published so that we can determine
// which descendent nodes are implicitly not published
descendants = _contentService.GetPagedDescendants(contentParentId, pageIndex, pageSize, out total, "level", Direction.Ascending, true, (string)null);
}
//if specific types are declared we need to post filter them
@@ -412,7 +415,7 @@ namespace UmbracoExamine
{
content = descendants.ToArray();
}
AddNodesToIndex(GetSerializedContent(content), type);
AddNodesToIndex(GetSerializedContent(content, notPublished).WhereNotNull(), type);
pageIndex++;
} while (content.Length == pageSize);
@@ -468,12 +471,28 @@ namespace UmbracoExamine
}
}
private IEnumerable<XElement> GetSerializedContent(IEnumerable<IContent> content)
{
var serializer = new EntityXmlSerializer();
private IEnumerable<XElement> GetSerializedContent(IEnumerable<IContent> content, ISet<string> notPublished)
{
foreach (var c in content)
{
var xml = serializer.Serialize(
if (SupportUnpublishedContent == false)
{
//if we don't support published content and this is not published then track it and return null
if (c.Published == false)
{
notPublished.Add(c.Path);
yield return null;
}
//if we don't support published content, check if this content item exists underneath any already tracked
//unpublished content and if so return null;
if (notPublished.Any(path => c.Path.StartsWith(string.Format("{0},", path))))
{
yield return null;
}
}
var xml = _serializer.Serialize(
_contentService,
_dataTypeService,
_userService,