From d671caf3ab0d5836c0d1ce4046a8b357360b8b40 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 3 Jan 2017 14:36:06 +1100 Subject: [PATCH 1/3] moves static query to lazily initialize --- src/UmbracoExamine/UmbracoContentIndexer.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/UmbracoExamine/UmbracoContentIndexer.cs b/src/UmbracoExamine/UmbracoContentIndexer.cs index 5acd5a077b..478f4a23fc 100644 --- a/src/UmbracoExamine/UmbracoContentIndexer.cs +++ b/src/UmbracoExamine/UmbracoContentIndexer.cs @@ -142,7 +142,7 @@ namespace UmbracoExamine _userService = userService; _contentTypeService = contentTypeService; } - + #endregion #region Constants & Fields @@ -365,7 +365,7 @@ namespace UmbracoExamine /// /// This is a static query, it's parameters don't change so store statically /// - private static readonly IQuery PublishedQuery = Query.Builder.Where(x => x.Published == true); + private IQuery _publishedQuery; protected override void PerformIndexAll(string type) { @@ -393,8 +393,13 @@ namespace UmbracoExamine } else { + if (_publishedQuery == null) + { + _publishedQuery = Query.Builder.Where(x => x.Published == true); + } + //add the published filter - descendants = _contentService.GetPagedDescendants(contentParentId, pageIndex, pageSize, out total, "Path", Direction.Ascending, true, PublishedQuery); + descendants = _contentService.GetPagedDescendants(contentParentId, pageIndex, pageSize, out total, "Path", Direction.Ascending, true, _publishedQuery); } //if specific types are declared we need to post filter them From c871a711dd74dc90a2d92158e2e635414a8b1e88 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 3 Jan 2017 16:43:54 +1100 Subject: [PATCH 2/3] 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 --- src/UmbracoExamine/UmbracoContentIndexer.cs | 41 +++++++++++++++------ 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/UmbracoExamine/UmbracoContentIndexer.cs b/src/UmbracoExamine/UmbracoContentIndexer.cs index 478f4a23fc..aa70162b31 100644 --- a/src/UmbracoExamine/UmbracoContentIndexer.cs +++ b/src/UmbracoExamine/UmbracoContentIndexer.cs @@ -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 /// /// 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(); + do { long total; @@ -398,8 +400,9 @@ namespace UmbracoExamine _publishedQuery = Query.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 GetSerializedContent(IEnumerable content) - { - var serializer = new EntityXmlSerializer(); + private IEnumerable GetSerializedContent(IEnumerable content, ISet 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, From 7a661c1b48d67b0808bfffc61f956d4769b00fe4 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 3 Jan 2017 17:16:07 +1100 Subject: [PATCH 3/3] clears the tracked paths collection just to possible make GC a bit happier --- src/UmbracoExamine/UmbracoContentIndexer.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/UmbracoExamine/UmbracoContentIndexer.cs b/src/UmbracoExamine/UmbracoContentIndexer.cs index aa70162b31..efc3e4a214 100644 --- a/src/UmbracoExamine/UmbracoContentIndexer.cs +++ b/src/UmbracoExamine/UmbracoContentIndexer.cs @@ -419,6 +419,8 @@ namespace UmbracoExamine pageIndex++; } while (content.Length == pageSize); + notPublished.Clear(); + break; case IndexTypes.Media: var mediaParentId = -1;