Cleans up paged methods of IContentService to use the Ordering parameter for consistency
This commit is contained in:
@@ -78,17 +78,6 @@ namespace Umbraco.Core.Services
|
||||
/// </summary>
|
||||
IEnumerable<IContent> GetByIds(IEnumerable<Guid> ids);
|
||||
|
||||
/// <summary>
|
||||
/// Gets paged documents of a content content
|
||||
/// </summary>
|
||||
/// <param name="contentType">The page number.</param>
|
||||
/// <param name="pageIndex">The page number.</param>
|
||||
/// <param name="pageSize">The page size.</param>
|
||||
/// <param name="totalRecords">Total number of documents.</param>
|
||||
/// <param name="filter">Search text filter.</param>
|
||||
/// <param name="ordering">Ordering infos.</param>
|
||||
IEnumerable<IContent> GetPagedOfType(int contentType, long pageIndex, int pageSize, out long totalRecords, IQuery<IContent> filter = null, Ordering ordering = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets documents at a given level.
|
||||
/// </summary>
|
||||
@@ -193,7 +182,7 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="orderDirection">The ordering direction.</param>
|
||||
/// <param name="filter">Search text filter.</param>
|
||||
IEnumerable<IContent> GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalRecords,
|
||||
string orderBy = "Path", Direction orderDirection = Direction.Ascending, string filter = "");
|
||||
string filter = null, Ordering ordering = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets descendant documents of a given parent.
|
||||
@@ -207,7 +196,31 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="orderBySystemField">A flag indicating whether the ordering field is a system field.</param>
|
||||
/// <param name="filter">Query filter.</param>
|
||||
IEnumerable<IContent> GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalRecords,
|
||||
string orderBy, Direction orderDirection, bool orderBySystemField, IQuery<IContent> filter);
|
||||
IQuery<IContent> filter, Ordering ordering = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets paged documents of a content content
|
||||
/// </summary>
|
||||
/// <param name="contentTypeId">The page number.</param>
|
||||
/// <param name="pageIndex">The page number.</param>
|
||||
/// <param name="pageSize">The page size.</param>
|
||||
/// <param name="totalRecords">Total number of documents.</param>
|
||||
/// <param name="filter">Search text filter.</param>
|
||||
/// <param name="ordering">Ordering infos.</param>
|
||||
IEnumerable<IContent> GetPagedOfType(int contentTypeId, long pageIndex, int pageSize, out long totalRecords,
|
||||
IQuery<IContent> filter, Ordering ordering = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets paged documents for specified content types
|
||||
/// </summary>
|
||||
/// <param name="contentTypeIds">The page number.</param>
|
||||
/// <param name="pageIndex">The page number.</param>
|
||||
/// <param name="pageSize">The page size.</param>
|
||||
/// <param name="totalRecords">Total number of documents.</param>
|
||||
/// <param name="filter">Search text filter.</param>
|
||||
/// <param name="ordering">Ordering infos.</param>
|
||||
IEnumerable<IContent> GetPagedOfTypes(int[] contentTypeIds, long pageIndex, int pageSize, out long totalRecords,
|
||||
IQuery<IContent> filter, Ordering ordering = null);
|
||||
|
||||
/// <summary>
|
||||
/// Counts documents of a given document type.
|
||||
|
||||
@@ -405,6 +405,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetPagedOfType(int contentTypeId, long pageIndex, int pageSize, out long totalRecords, IQuery<IContent> filter, Ordering ordering = null)
|
||||
{
|
||||
if(pageIndex < 0) throw new ArgumentOutOfRangeException(nameof(pageIndex));
|
||||
@@ -422,6 +423,24 @@ namespace Umbraco.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetPagedOfTypes(int[] contentTypeIds, long pageIndex, int pageSize, out long totalRecords, IQuery<IContent> filter, Ordering ordering = null)
|
||||
{
|
||||
if (pageIndex < 0) throw new ArgumentOutOfRangeException(nameof(pageIndex));
|
||||
if (pageSize <= 0) throw new ArgumentOutOfRangeException(nameof(pageSize));
|
||||
|
||||
if (ordering == null)
|
||||
ordering = Ordering.By("sortOrder");
|
||||
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return _documentRepository.GetPage(
|
||||
Query<IContent>().Where(x => contentTypeIds.Contains(x.ContentTypeId)),
|
||||
pageIndex, pageSize, out totalRecords, filter, ordering);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of <see cref="IContent"/> objects by Level
|
||||
/// </summary>
|
||||
@@ -574,18 +593,24 @@ namespace Umbraco.Core.Services.Implement
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalChildren, string orderBy = "Path", Direction orderDirection = Direction.Ascending, string filter = "")
|
||||
public IEnumerable<IContent> GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalChildren,
|
||||
string filter = null, Ordering ordering = null)
|
||||
//string orderBy = "Path", Direction orderDirection = Direction.Ascending, string filter = "")
|
||||
{
|
||||
var filterQuery = filter.IsNullOrWhiteSpace()
|
||||
? null
|
||||
: Query<IContent>().Where(x => x.Name.Contains(filter));
|
||||
|
||||
return GetPagedDescendants(id, pageIndex, pageSize, out totalChildren, orderBy, orderDirection, true, filterQuery);
|
||||
return GetPagedDescendants(id, pageIndex, pageSize, out totalChildren, filterQuery, ordering);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalChildren, string orderBy, Direction orderDirection, bool orderBySystemField, IQuery<IContent> filter)
|
||||
public IEnumerable<IContent> GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalChildren,
|
||||
IQuery<IContent> filter, Ordering ordering = null)
|
||||
{
|
||||
if (ordering == null)
|
||||
ordering = Ordering.By("Path");
|
||||
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
@@ -599,22 +624,26 @@ namespace Umbraco.Core.Services.Implement
|
||||
totalChildren = 0;
|
||||
return Enumerable.Empty<IContent>();
|
||||
}
|
||||
return GetPagedDescendantsLocked(contentPath[0].Path, pageIndex, pageSize, out totalChildren, orderBy, orderDirection, orderBySystemField, filter);
|
||||
return GetPagedDescendantsLocked(contentPath[0].Path, pageIndex, pageSize, out totalChildren, filter, ordering);
|
||||
}
|
||||
return GetPagedDescendantsLocked(null, pageIndex, pageSize, out totalChildren, orderBy, orderDirection, orderBySystemField, filter);
|
||||
return GetPagedDescendantsLocked(null, pageIndex, pageSize, out totalChildren, filter, ordering);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<IContent> GetPagedDescendantsLocked(string contentPath, long pageIndex, int pageSize, out long totalChildren, string orderBy, Direction orderDirection, bool orderBySystemField, IQuery<IContent> filter)
|
||||
private IEnumerable<IContent> GetPagedDescendantsLocked(string contentPath, long pageIndex, int pageSize, out long totalChildren,
|
||||
IQuery<IContent> filter, Ordering ordering)
|
||||
{
|
||||
if (pageIndex < 0) throw new ArgumentOutOfRangeException(nameof(pageIndex));
|
||||
if (pageSize <= 0) throw new ArgumentOutOfRangeException(nameof(pageSize));
|
||||
if (filter == null) throw new ArgumentNullException(nameof(filter));
|
||||
|
||||
if (ordering == null) throw new ArgumentNullException(nameof(ordering));
|
||||
|
||||
var query = Query<IContent>();
|
||||
if (!contentPath.IsNullOrWhiteSpace())
|
||||
query.Where(x => x.Path.SqlStartsWith($"{contentPath},", TextColumnType.NVarchar));
|
||||
|
||||
return _documentRepository.GetPage(query, pageIndex, pageSize, out totalChildren, filter, Ordering.By(orderBy, orderDirection, isCustomField: !orderBySystemField));
|
||||
return _documentRepository.GetPage(query, pageIndex, pageSize, out totalChildren, filter, ordering);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1412,7 +1441,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
while (page * pageSize < total)
|
||||
{
|
||||
//get descendants - ordered from deepest to shallowest
|
||||
var descendants = GetPagedDescendants(content.Id, page, pageSize, out total, "Path", Direction.Descending);
|
||||
var descendants = GetPagedDescendants(content.Id, page, pageSize, out total, ordering: Ordering.By("Path", Direction.Descending));
|
||||
foreach (var c in descendants)
|
||||
DoDelete(c);
|
||||
}
|
||||
@@ -1645,7 +1674,7 @@ namespace Umbraco.Core.Services.Implement
|
||||
var total = long.MaxValue;
|
||||
while(page * pageSize < total)
|
||||
{
|
||||
var descendants = GetPagedDescendantsLocked(originalPath, page++, pageSize, out total, "Path", Direction.Ascending, true, null);
|
||||
var descendants = GetPagedDescendantsLocked(originalPath, page++, pageSize, out total, null, Ordering.By("Path", Direction.Ascending));
|
||||
foreach (var descendant in descendants)
|
||||
{
|
||||
moves.Add(Tuple.Create(descendant, descendant.Path)); // capture original path
|
||||
|
||||
@@ -258,7 +258,8 @@ namespace Umbraco.Examine
|
||||
else
|
||||
{
|
||||
//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,
|
||||
_publishedQuery, Ordering.By("Path", Direction.Ascending));
|
||||
}
|
||||
|
||||
//if specific types are declared we need to post filter them
|
||||
|
||||
@@ -1718,7 +1718,7 @@ namespace Umbraco.Tests.Services
|
||||
// Act
|
||||
contentService.DeleteOfType(contentType.Id);
|
||||
var rootContent = contentService.GetRootContent();
|
||||
var contents = contentService.GetPagedOfType(contentType.Id, 0, int.MaxValue, out var _);
|
||||
var contents = contentService.GetPagedOfType(contentType.Id, 0, int.MaxValue, out var _, null);
|
||||
|
||||
// Assert
|
||||
Assert.That(rootContent.Any(), Is.False);
|
||||
|
||||
@@ -71,11 +71,11 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
|
||||
contentService = Mock.Of<IContentService>(
|
||||
x => x.GetPagedDescendants(
|
||||
It.IsAny<int>(), It.IsAny<long>(), It.IsAny<int>(), out longTotalRecs, It.IsAny<string>(), It.IsAny<Direction>(), It.IsAny<string>())
|
||||
It.IsAny<int>(), It.IsAny<long>(), It.IsAny<int>(), out longTotalRecs, It.IsAny<string>(), It.IsAny<Ordering>())
|
||||
==
|
||||
allRecs
|
||||
&& x.GetPagedDescendants(
|
||||
It.IsAny<int>(), It.IsAny<long>(), It.IsAny<int>(), out longTotalRecs, It.IsAny<string>(), It.IsAny<Direction>(), It.IsAny<bool>(), It.IsAny<IQuery<IContent>>())
|
||||
It.IsAny<int>(), It.IsAny<long>(), It.IsAny<int>(), out longTotalRecs, It.IsAny<IQuery<IContent>>(), It.IsAny<Ordering>())
|
||||
==
|
||||
allRecs);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
.ToArray();
|
||||
var contentService = Mock.Of<IContentService>(
|
||||
x => x.GetPagedDescendants(
|
||||
It.IsAny<int>(), It.IsAny<long>(), It.IsAny<int>(), out totalRecs, It.IsAny<string>(), It.IsAny<Direction>(), It.IsAny<bool>(), It.IsAny<IQuery<IContent>>())
|
||||
It.IsAny<int>(), It.IsAny<long>(), It.IsAny<int>(), out totalRecs, It.IsAny<IQuery<IContent>>(), It.IsAny<Ordering>())
|
||||
==
|
||||
allRecs);
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ using Umbraco.Web.Cache;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.PropertyEditors;
|
||||
using Umbraco.Examine;
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
|
||||
namespace Umbraco.Web.Search
|
||||
{
|
||||
@@ -351,21 +352,42 @@ namespace Umbraco.Web.Search
|
||||
|
||||
const int pageSize = 500;
|
||||
|
||||
//Re-index all content of these types
|
||||
foreach(var id in refreshedIds.Concat(otherIds).Distinct())
|
||||
{
|
||||
if (refreshedIds.Count > 0 || otherIds.Count > 0)
|
||||
{
|
||||
var page = 0;
|
||||
var total = long.MaxValue;
|
||||
while (page * pageSize < total)
|
||||
{
|
||||
var contentToRefresh = _services.ContentService.GetPagedOfType(id, page++, pageSize, out total);
|
||||
foreach(var c in contentToRefresh)
|
||||
var contentToRefresh = _services.ContentService.GetPagedOfTypes(
|
||||
//Re-index all content of these types
|
||||
refreshedIds.Concat(otherIds).Distinct().ToArray(),
|
||||
page++, pageSize, out total, null,
|
||||
//order by shallowest to deepest, this allows us to check it's published state without checking every item
|
||||
Ordering.By("Path", Direction.Ascending));
|
||||
|
||||
//track which Ids have their paths are published
|
||||
var publishChecked = new Dictionary<int, bool>();
|
||||
|
||||
foreach (var c in contentToRefresh)
|
||||
{
|
||||
//TODO: We might have to order by Path ascending or something since we're going to need to check
|
||||
// contentService.IsPathPublished(content) but we don't want to make that check for every content item
|
||||
IContent published = null;
|
||||
if (c.Published && contentService.IsPathPublished(c))
|
||||
published = c;
|
||||
if (c.Published)
|
||||
{
|
||||
if (publishChecked.TryGetValue(c.ParentId, out var isPublished))
|
||||
{
|
||||
//if the parent's published path has already been verified then this is published
|
||||
if (isPublished)
|
||||
published = c;
|
||||
}
|
||||
else
|
||||
{
|
||||
//nothing by parent id, so query the service and cache the result for the next child to check against
|
||||
isPublished = contentService.IsPathPublished(c);
|
||||
publishChecked[c.Id] = isPublished;
|
||||
if (isPublished)
|
||||
published = c;
|
||||
}
|
||||
}
|
||||
|
||||
ReIndexForContent(c, published);
|
||||
}
|
||||
@@ -460,7 +482,10 @@ namespace Umbraco.Web.Search
|
||||
var total = long.MaxValue;
|
||||
while(page * pageSize < total)
|
||||
{
|
||||
var descendants = contentService.GetPagedDescendants(content.Id, page++, pageSize, out total);
|
||||
var descendants = contentService.GetPagedDescendants(content.Id, page++, pageSize, out total,
|
||||
//order by shallowest to deepest, this allows us to check it's published state without checking every item
|
||||
ordering: Ordering.By("Path", Direction.Ascending));
|
||||
|
||||
foreach (var descendant in descendants)
|
||||
{
|
||||
published = null;
|
||||
|
||||
Reference in New Issue
Block a user