From 890309bc11e42e885134b3b1fde8c6bb6c68341e Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 19 Aug 2019 17:18:45 +1000 Subject: [PATCH] Fixes SetAllFastSorted and sort orders --- .../Testing/Objects/TestDataSource.cs | 9 ++- .../PublishedCache/NuCache/ContentStore.cs | 13 ++-- .../NuCache/DataSource/DatabaseDataSource.cs | 16 ++--- .../NuCache/DataSource/IDataSource.cs | 62 ++++++++++++++++++- .../NuCache/PublishedSnapshotService.cs | 10 +-- 5 files changed, 87 insertions(+), 23 deletions(-) diff --git a/src/Umbraco.Tests/Testing/Objects/TestDataSource.cs b/src/Umbraco.Tests/Testing/Objects/TestDataSource.cs index 72fb89ab82..2d3b058421 100644 --- a/src/Umbraco.Tests/Testing/Objects/TestDataSource.cs +++ b/src/Umbraco.Tests/Testing/Objects/TestDataSource.cs @@ -29,17 +29,24 @@ namespace Umbraco.Tests.Testing.Objects public IEnumerable GetAllContentSources(IScope scope) => Kits.Values .OrderBy(x => x.Node.Level) + .ThenBy(x => x.Node.ParentContentId) + .ThenBy(x => x.Node.SortOrder) .Select(x => x.Clone()); public IEnumerable GetBranchContentSources(IScope scope, int id) => Kits.Values .Where(x => x.Node.Path.EndsWith("," + id) || x.Node.Path.Contains("," + id + ",")) - .OrderBy(x => x.Node.Level).ThenBy(x => x.Node.SortOrder) + .OrderBy(x => x.Node.Level) + .ThenBy(x => x.Node.ParentContentId) + .ThenBy(x => x.Node.SortOrder) .Select(x => x.Clone()); public IEnumerable GetTypeContentSources(IScope scope, IEnumerable ids) => Kits.Values .Where(x => ids.Contains(x.ContentTypeId)) + .OrderBy(x => x.Node.Level) + .ThenBy(x => x.Node.ParentContentId) + .ThenBy(x => x.Node.SortOrder) .Select(x => x.Clone()); public ContentNodeKit GetMediaSource(IScope scope, int id) diff --git a/src/Umbraco.Web/PublishedCache/NuCache/ContentStore.cs b/src/Umbraco.Web/PublishedCache/NuCache/ContentStore.cs index 86fc69c302..d07602dd29 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/ContentStore.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/ContentStore.cs @@ -609,22 +609,21 @@ namespace Umbraco.Web.PublishedCache.NuCache // NextSiblingContentId ContentNode prev = null; - var currLevel = 0; + ContentNode currParent = null; foreach (var kit in kits) { - if (currLevel != kit.Node.Level) - { - prev = null; //reset since we're on a new level - currLevel = kit.Node.Level; - } - if (!BuildKit(kit, out var parentLink)) { ok = false; continue; // skip that one } + if (currParent != null && currParent.Id != parentLink.Value.Id) + prev = null; //changed parent + + currParent = parentLink.Value; + _logger.Debug($"Set {kit.Node.Id} with parent {kit.Node.ParentContentId}"); SetValueLocked(_contentNodes, kit.Node.Id, kit.Node); diff --git a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/DatabaseDataSource.cs b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/DatabaseDataSource.cs index 3b66bd52d0..f07ea7db6b 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/DatabaseDataSource.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/DatabaseDataSource.cs @@ -67,7 +67,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource { var sql = ContentSourcesSelect(scope) .Where(x => x.NodeObjectType == Constants.ObjectTypes.Document && x.NodeId == id && !x.Trashed) - .OrderBy(x => x.Level, x => x.SortOrder); + .OrderBy(x => x.Level, x => x.ParentId, x => x.SortOrder); var dto = scope.Database.Fetch(sql).FirstOrDefault(); return dto == null ? new ContentNodeKit() : CreateContentNodeKit(dto); @@ -77,7 +77,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource { var sql = ContentSourcesSelect(scope) .Where(x => x.NodeObjectType == Constants.ObjectTypes.Document && !x.Trashed) - .OrderBy(x => x.Level, x => x.SortOrder); + .OrderBy(x => x.Level, x => x.ParentId, x => x.SortOrder); return scope.Database.Query(sql).Select(CreateContentNodeKit); } @@ -91,7 +91,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource .Where(x => x.NodeObjectType == Constants.ObjectTypes.Document && !x.Trashed) .Where(x => x.NodeId == id, "x") - .OrderBy(x => x.Level, x => x.SortOrder); + .OrderBy(x => x.Level, x => x.ParentId, x => x.SortOrder); return scope.Database.Query(sql).Select(CreateContentNodeKit); } @@ -103,7 +103,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource var sql = ContentSourcesSelect(scope) .Where(x => x.NodeObjectType == Constants.ObjectTypes.Document && !x.Trashed) .WhereIn(x => x.ContentTypeId, ids) - .OrderBy(x => x.Level, x => x.SortOrder); + .OrderBy(x => x.Level, x => x.ParentId, x => x.SortOrder); return scope.Database.Query(sql).Select(CreateContentNodeKit); } @@ -140,7 +140,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource { var sql = MediaSourcesSelect(scope) .Where(x => x.NodeObjectType == Constants.ObjectTypes.Media && x.NodeId == id && !x.Trashed) - .OrderBy(x => x.Level, x => x.SortOrder); + .OrderBy(x => x.Level, x => x.ParentId, x => x.SortOrder); var dto = scope.Database.Fetch(sql).FirstOrDefault(); return dto == null ? new ContentNodeKit() : CreateMediaNodeKit(dto); @@ -150,7 +150,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource { var sql = MediaSourcesSelect(scope) .Where(x => x.NodeObjectType == Constants.ObjectTypes.Media && !x.Trashed) - .OrderBy(x => x.Level, x => x.SortOrder); + .OrderBy(x => x.Level, x => x.ParentId, x => x.SortOrder); return scope.Database.Query(sql).Select(CreateMediaNodeKit); } @@ -164,7 +164,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource .Where(x => x.NodeObjectType == Constants.ObjectTypes.Media && !x.Trashed) .Where(x => x.NodeId == id, "x") - .OrderBy(x => x.Level, x => x.SortOrder); + .OrderBy(x => x.Level, x => x.ParentId, x => x.SortOrder); return scope.Database.Query(sql).Select(CreateMediaNodeKit); } @@ -176,7 +176,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource var sql = MediaSourcesSelect(scope) .Where(x => x.NodeObjectType == Constants.ObjectTypes.Media && !x.Trashed) .WhereIn(x => x.ContentTypeId, ids) - .OrderBy(x => x.Level, x => x.SortOrder); + .OrderBy(x => x.Level, x => x.ParentId, x => x.SortOrder); return scope.Database.Query(sql).Select(CreateMediaNodeKit); } diff --git a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/IDataSource.cs b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/IDataSource.cs index 941c7d0caa..ec3ab38e84 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/IDataSource.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/IDataSource.cs @@ -8,14 +8,70 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource /// internal interface IDataSource { + //TODO: For these required sort orders, would sorting on Path 'just work'? + ContentNodeKit GetContentSource(IScope scope, int id); - IEnumerable GetAllContentSources(IScope scope); // must order by level, sortOrder - IEnumerable GetBranchContentSources(IScope scope, int id); // must order by level, sortOrder + + /// + /// Returns all content ordered by level + sortOrder + /// + /// + /// + /// + /// MUST be ordered by level + parentId + sortOrder! + /// + IEnumerable GetAllContentSources(IScope scope); + + /// + /// Returns branch for content ordered by level + sortOrder + /// + /// + /// + /// + /// MUST be ordered by level + parentId + sortOrder! + /// + IEnumerable GetBranchContentSources(IScope scope, int id); + + /// + /// Returns content by Ids ordered by level + sortOrder + /// + /// + /// + /// + /// MUST be ordered by level + parentId + sortOrder! + /// IEnumerable GetTypeContentSources(IScope scope, IEnumerable ids); ContentNodeKit GetMediaSource(IScope scope, int id); - IEnumerable GetAllMediaSources(IScope scope); // must order by level, sortOrder + + /// + /// Returns all media ordered by level + sortOrder + /// + /// + /// + /// + /// MUST be ordered by level + parentId + sortOrder! + /// + IEnumerable GetAllMediaSources(IScope scope); + + /// + /// Returns branch for media ordered by level + sortOrder + /// + /// + /// + /// + /// MUST be ordered by level + parentId + sortOrder! + /// IEnumerable GetBranchMediaSources(IScope scope, int id); // must order by level, sortOrder + + /// + /// Returns media by Ids ordered by level + sortOrder + /// + /// + /// + /// + /// MUST be ordered by level + parentId + sortOrder! + /// IEnumerable GetTypeMediaSources(IScope scope, IEnumerable ids); } } diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs index 5a7ae9e899..f1141da376 100755 --- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs @@ -349,7 +349,7 @@ namespace Umbraco.Web.PublishedCache.NuCache _localContentDb?.Clear(); - // IMPORTANT GetAllContentSources sorts kits by level + sortOrder + // IMPORTANT GetAllContentSources sorts kits by level + parentId + sortOrder var kits = _dataSource.GetAllContentSources(scope); return _contentStore.SetAllFastSorted(kits); } @@ -368,7 +368,8 @@ namespace Umbraco.Web.PublishedCache.NuCache var kits = _localContentDb.Select(x => x.Value) .OrderBy(x => x.Node.Level) - .ThenBy(x => x.Node.SortOrder); // IMPORTANT sort by level + sortOrder + .ThenBy(x => x.Node.ParentContentId) + .ThenBy(x => x.Node.SortOrder); // IMPORTANT sort by level + parentId + sortOrder return _contentStore.SetAllFastSorted(kits); } } @@ -424,7 +425,7 @@ namespace Umbraco.Web.PublishedCache.NuCache _localMediaDb?.Clear(); _logger.Debug("Loading media from database..."); - // IMPORTANT GetAllMediaSources sorts kits by level + sortOrder + // IMPORTANT GetAllMediaSources sorts kits by level + parentId + sortOrder var kits = _dataSource.GetAllMediaSources(scope); return _mediaStore.SetAllFastSorted(kits); } @@ -443,7 +444,8 @@ namespace Umbraco.Web.PublishedCache.NuCache var kits = _localMediaDb.Select(x => x.Value) .OrderBy(x => x.Node.Level) - .ThenBy(x => x.Node.SortOrder); // IMPORTANT sort by level + order; + .ThenBy(x => x.Node.ParentContentId) + .ThenBy(x => x.Node.SortOrder); // IMPORTANT sort by level + parentId + sortOrder return _mediaStore.SetAllFastSorted(kits); }