Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Neil 36 posts 200 karma points
    17 days ago
    Neil
    0

    Get content by type (without ContentAtXPath).

    With the obsoletion of ContentAtXPath and ContentSingleAtXPath, does anyone know the most performant way to get content by type?

    Looping through the entire site and checking the type of each one in turn seems less than performant.

  • Marc Goodson 2046 posts 13491 karma points MVP 8x c-trib
    1 week ago
    Marc Goodson
    100

    Hi Neil

    Paul Sea and Tim Payne did a talk at Umbraco Spark a while back when Umbraco moved from V7 to V8 and from XML Published Cache to NuCache BTree implementations, and this is the point in time when using XPath became slower than NuCache, because the published cache was no longer stored as XML.

    The slides are here:

    https://umbracospark.com/media/p0xgaq2u/querying-umbraco.pptx

    and still a good resource to flip through to understand the change, they benchmarked lots of different approaches and showed that DescendentsOfType was particular quick! or at least reversing the previous knowledge of use XPath for this kind of thing..

    All depends on the context and size of your site and what you are trying to do, query wise, but now using NuCache direct using Descendents/Children etc is quicker than XPath, because in order ot generate the XML for XPath to be actioned, the NuCache needs to be queried first anyway!

    There is a good cheat sheet here of the updated syntax for the dot net core versions of Umbraco, if that helps as a reference.

    https://docs.umbraco.com/umbraco-cms/fundamentals/design/templates/razor-cheatsheet

    regards

    Marc

  • Neil 36 posts 200 karma points
    1 week ago
    Neil
    0

    Thanks for that Marc.

    Any idea what would be the replacement for Umbraco:CMS:Content:Error404Collection:ContentXPath in appsettings.json, where hard coding a GUID is not an option?

    The official docs still recommend Xpath for cloud environments;

    If you are hosting your site on Umbraco Cloud, the best approach would be using an XPath statement. This is because content IDs might differ across Cloud environments.

    https://docs.umbraco.com/umbraco-cms/v/10.latest-lts/tutorials/custom-error-page

  • Marc Goodson 2046 posts 13491 karma points MVP 8x c-trib
    1 week ago
    Marc Goodson
    0

    Hi Neil

    For that instance, I think you are still going to be using XPath, in Umbraco 14 XPath will be removed and a new 'dynamic' start node functionality is going to be introduced to do all those relative Xpath type things that still linger on.

    https://github.com/umbraco/Announcements/issues/10#issuecomment-1761671191

    For 404's I've not used that setting for a long time, instead I've been using a LastChanceContentFinder:

    https://docs.umbraco.com/umbraco-cms/implementation/custom-routing#last-chance-icontentfinder

    that I then work out which site is being requested from the domain of the url that is 'about to 404', then find the page not found doc type within that site and return that...

    There is a package that has a UI for setting a page not found page in a multisite setup that has an implementation of LastChanceContentFinder that might be worth a look.

    https://marketplace.umbraco.com/package/hotchilli.umbraco.pagenotfound

    regards

    Marc

  • Neil 36 posts 200 karma points
    1 week ago
    Neil
    0

    Cheers Marc, most helpful 👍

Please Sign in or register to post replies

Write your reply to:

Draft