Copied to clipboard

Flag this post as spam?

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


  • SSB85 2 posts 32 karma points
    May 30, 2020 @ 12:23
    SSB85
    0

    Using Performant XPath Querying To Get Back Child Nodes By Path

    I am trying to ensure my Umbraco site is using the most efficient way to get back large sets of data as the site grows. From reading the Common Pitfalls documentation, querying via XPath seems the way to go.

    I understand how to get back all documents based on a property or alias. However, I cannot seem to find a way to get back documents based on a path using ContentAtXPath method.

    Umbraco.ContentAtXPath("//* [@isDoc]/descendant::/Blog [@isDoc]")

    I am trying to run that within a SurfaceController.

    I've seen other posts where quite nice querying was carried out in older versions of Umbraco including sorting etc.

    I'd appreciate if someone could point me in the right direction.

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    May 31, 2020 @ 09:05
    Marc Goodson
    100

    Hi SSB85

    It's all change in Umbraco V8!!

    In V7 and previous versions the published cache of content was stored as an XML file in memory, and consequently XPATH was generally always the quickest fastest way to retrieve things...

    ... But in V8 the published cache is stored using a new NuCache mechanism which is not in XML format, (XPATH has been retained, for some of the concepts in Umbraco like 'setting the start node in a multinode tree picker' - but it is no longer suggested to use XPATH for querying on your site implementation - you can - but it's no longer the 'quickest' method.

    The common pitfalls documentation hasn't been updated for V8!

    Paul Seal and Tim Payne gave a talk at Umbraco Spark - earlier this year regarding their investigations into peformance and querying in V8 and their slides are available here;

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

    The slides have some useful examples, and show the timings of accessing content in different ways between V7 and V8.. showing of the places where certain strategies are faster than others.

    regards

    Marc

  • SSB85 2 posts 32 karma points
    May 31, 2020 @ 11:16
    SSB85
    0

    Hi Marc!

    Thanks for the additional info and I have just gone through Paul and Tim's slides.

    Just to be sure I am understanding correctly, LINQ operations seem to be quicker in all the performance tests. So if I had 5000 pages and needed to do the following query:

    IEnumerable<IPublishedContent> umbracoPages = startPage
                                                        .DescendantsOfType("blogpost")
                                                        .Where(p => !p.Value<bool>("navigationHide"))
                                                        .Take(5)
                                                        .Skip(2)
                                                        .OrderBy(p => p.SortOrder);
    

    That wouldn't considered bad practice as I am getting backing all the types of "blogpost", just getting back 5 items and then ordering?

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Jun 01, 2020 @ 07:12
    Marc Goodson
    0

    Hi SSB85,

    Yes, I think that is the conclusion they came to.

    You can always measure how long a piece of code takes to execute on your site, using the MiniProfiler: and wrapping the lines of code in an IProfiler 'step'

    https://our.umbraco.com/documentation/Getting-Started/Code/Debugging/#writing-to-the-miniprofiler

    But although it goes against all the ingrained Umbraco knowledge of previous versions, Linq with NuCache is the suggested approach.

    If you are filtering by 'text' eg Where(f=>f.Value

    ... it depends on the context, but if you use the Miniprofiler you can be sure in your context what the expense of a particular query is.

    regards

    Marc

  • Amir Khan 1282 posts 2739 karma points
    May 31, 2020 @ 20:40
    Amir Khan
    0

    This is just a thought, and don't know if it will work, but if you put the take / skip before the .DescendantsOfType("blogpost") does it still loop through all the nodes?

Please Sign in or register to post replies

Write your reply to:

Draft