Skip to content

V15: Fix friendly content extension performance#17779

Merged
bergmania merged 7 commits intorelease/15.1from
v15/hotfix/fix-friendly-content-extension-performance
Dec 11, 2024
Merged

V15: Fix friendly content extension performance#17779
bergmania merged 7 commits intorelease/15.1from
v15/hotfix/fix-friendly-content-extension-performance

Conversation

@Zeegaan
Copy link
Member

@Zeegaan Zeegaan commented Dec 11, 2024

FIxes #17768

Notes

  • We stopped caching null values with V15: Add custom serializer for hybrid cache #17727, this uncovered a bug with all our FriendlyPublishedContentExtensions, as it would not filter by only published content
  • This PR refactors every single one of those (and obsoleted the old ones), to use the IPublishStatusQuery service, to check if a given key is published or not, this turns a 30s operation into 0.5s (and this is cached), and after caching, down to 1-10ms depending on size 😁

How to test

  • Create a doc type with allow as root set to true
  • Create a doc type named "Child"
  • Allow "Child" as child on the first doc type
  • Create a parent node
  • Create 500 child nodes
  • Try using the methods, like Children or Descendants it should no longer take multiple seconds
  • Here is some sample code to help with creation of child nodes, and quering of .Children
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Core.Services;

namespace Umbraco.Cms.Web.UI;

[ApiController]
[Route("[controller]/[action]")]
public class TestController : Controller
{
    private readonly IPublishedContentCache _publishedContentCache;
    private readonly IContentService _contentService;

    public TestController(IPublishedContentCache publishedContentCache, IContentService contentService)
    {
        _publishedContentCache = publishedContentCache;
        _contentService = contentService;
    }

    [HttpGet]
    public IActionResult Index(Guid? parentKey)
    {
        var content = _publishedContentCache.GetByIdAsync(parentKey ?? new Guid("119b7b3d-f24e-4d27-af98-7b8d14d62f9c")).GetAwaiter().GetResult();

        var children = content?.Descendants();

        var count = children?.Count();
        return Ok(count);
    }

    [HttpGet]
    public IActionResult CreateTestContent(Guid? parentKey)
    {
        // Create a variable for the GUID of the parent page - Catalogue, where you want to add a child item.
        var parentId = parentKey ?? Guid.Parse("119b7b3d-f24e-4d27-af98-7b8d14d62f9c");

        for (int i = 1; i < 5000; i++)
        {
            // Create a new child item of type 'Product'
            IContent demoproduct = _contentService.Create($"Child {i}", parentId, "child");

            // Set the value of the property with alias 'category'
            demoproduct.SetValue("title" , "Title of child " + i);

            // Save and publish the child item
            _contentService.Save(demoproduct);
        }

        return Ok();
    }
}

@Zeegaan Zeegaan requested a review from bergmania December 11, 2024 14:16
Copy link
Member

@bergmania bergmania left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to handle the empty culture in the Publish Status service, but besides that, i looks correct.

@bergmania bergmania merged commit 4f6fda7 into release/15.1 Dec 11, 2024
@bergmania bergmania deleted the v15/hotfix/fix-friendly-content-extension-performance branch December 11, 2024 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants