Copied to clipboard

Flag this post as spam?

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

  • Markus Johansson 1924 posts 5831 karma points MVP 2x c-trib
    Dec 18, 2019 @ 11:00
    Markus Johansson

    Most efficient way to get content by DocumentType / ContentType in V8


    I know that in Umbraco 7 when the XML-cache was still around the most efficient way to fetch all content nodes by its document type would be something like:

    var blogPosts = Umbraco.TypedContentAtXPath("//BlogPost");

    But in V8, with NuCache storing the object instances I guessing that a XPath-query would force all nodes to have to "convert" in to XML to perform a query like this? It feels like this could be a performance nightmare?

    Also this would perform some nested loop to query lots and lots of objects:

    var blogPosts = StartModel.Descendants<BlogPost>()

    What I can think of right now would be to use Examine to get all the nodes and then load them from the content cache, but maybe there is a better way?

    Anyone who knows what would be the most efficient way to query/load all nodes based on Document Type?

    // m

  • Jules 273 posts 584 karma points
    May 29, 2020 @ 12:51

    Did you ever find an answer for this?

    Seems very relevant even today. Hopefully this post will bring the subject back to life?


  • Matthew Wise 271 posts 1373 karma points MVP 5x c-trib
    May 29, 2020 @ 13:45
    Matthew Wise


    Xpath is really only in v8 for use with the Multi node tree picker.

    If I remember correctly:

    Linq is faster with a smaller amount of content vs Examine (depending on how its used)

    Paul Seal and Tim Payne did a talk on this at Umbraco Spark eariler this year the test repo is here -

    (you will need to run it to see the results)

    I know offroadcode have seen different results in some cases.


    EDIT - Slides are on

  • Harikrishna Parmar 43 posts 262 karma points c-trib
    May 29, 2020 @ 16:03
    Harikrishna Parmar

    Hi Markus, I think this will help you.

    var blogpost = Model.Root.AncestorOrSelf(BlogPost.ModelTypeAlias);
  • Jules 273 posts 584 karma points
    Jun 01, 2020 @ 13:00

    Does Model.Root have Ancestors?

    Do you mean DescendantsOrSelf?

  • Markus Johansson 1924 posts 5831 karma points MVP 2x c-trib
    Jun 01, 2020 @ 12:18
    Markus Johansson


    Thanks @Harikrishna, I know that this is an option but also might not be the best option since it will loop over all content in the entire site. In V7 this was quite slow. I guess this would work but I was looking for a solution similar to the one I posted but for V8.

    Until then I ended up using Examine to search for all the content and fetch the ones I need from the Content Cache.

    // m

Please Sign in or register to post replies

Write your reply to: