Copied to clipboard

Flag this post as spam?

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


  • Simone Chiaretta 134 posts 541 karma points c-trib
    Feb 16, 2016 @ 14:39
    Simone Chiaretta
    0

    Querying content in other branches of the node tree: what is the best practice?

    I'm interested in understanding which is best way of retrieving nodes that are located in a branch different from the one where my current node is.

    At the moment I'm doing:

    var entities = Umbraco.TypedContentAtRoot()
            .First()
            .DescendantsOrSelf("Taxonomy")
            .Where(x => x.Name == "Bodies");
    

    But I was wondering if, performance wise, it's better to first select the specific root, and then search only inside it.

    var entities = Umbraco.TypedContentAtRoot()
            .Single(x => x.DocumentTypeAlias == "Settings")
            .Descendants()
            .Where(x => x.DocumentTypeAlias == "Taxonomy" && x.Name == "Bodies");
    

    In theory I could also store in my app.config the actual node of which I need to list the children, but I'd prefer to avoid doing that.

  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    Feb 16, 2016 @ 15:57
    Alex Skrypnyk
    0

    Hi Simine,

    The best is - use Descendants never! In my opinion it's better to hardcode node id in config, it's much faster than doing Descdendants.

    Thanks

  • Simone Chiaretta 134 posts 541 karma points c-trib
    Feb 17, 2016 @ 11:26
    Simone Chiaretta
    0

    Don't really like hard-coding ids. Maybe going for navigating children and then children would it be faster?

    I mean, descendants gets everything, while with children you only search within the levels and branches you know.

  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    Feb 17, 2016 @ 11:31
    Alex Skrypnyk
    0

    Children and children is faster than descendants.

    I don't like hardcoding ids too, but as I understand you need some node, you don't need go through all site and find it, you know that this node you need, so as I understand id will be ok.

    Thanks

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Feb 18, 2016 @ 09:54
    Ismail Mayat
    0

    Examine all the things, so you can use examine searches to get stuff from different parts of the site its lightening quick.

Please Sign in or register to post replies

Write your reply to:

Draft