Use GetIdsFromPathReversed to avoid allocating the string values of the integers parsed
This commit is contained in:
committed by
Sebastiaan Janssen
parent
9e97f6028b
commit
b7bf30744a
@@ -1,5 +1,3 @@
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Umbraco.Cms.Core.DependencyInjection;
|
||||
@@ -88,19 +86,14 @@ internal sealed class PublicAccessService : RepositoryService, IPublicAccessServ
|
||||
{
|
||||
// Get all ids in the path for the content item and ensure they all
|
||||
// parse to ints that are not -1.
|
||||
var ids = contentPath.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(x => int.TryParse(x, NumberStyles.Integer, CultureInfo.InvariantCulture, out var val) ? val : -1)
|
||||
.Where(x => x != -1)
|
||||
.ToList();
|
||||
|
||||
// start with the deepest id
|
||||
ids.Reverse();
|
||||
// Start with the deepest id.
|
||||
IEnumerable<int> ids = contentPath.GetIdsFromPathReversed().Where(x => x != -1);
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
// This will retrieve from cache!
|
||||
var entries = _publicAccessRepository.GetMany().ToList();
|
||||
foreach (var id in CollectionsMarshal.AsSpan(ids))
|
||||
foreach (var id in ids)
|
||||
{
|
||||
PublicAccessEntry? found = entries.Find(x => x.ProtectedNodeId == id);
|
||||
if (found != null)
|
||||
|
||||
Reference in New Issue
Block a user