Copied to clipboard

Flag this post as spam?

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


  • Jeffrey Schoemaker 408 posts 2138 karma points MVP 8x c-trib
    May 03, 2012 @ 16:42
    Jeffrey Schoemaker
    0

    Umbraco - Fastest way to loop through a lot of nodes

    Hi all,

    for a project I have to loop through a lot of nodes (4000) that are stored in an alphabet-folder.

    RootNode

    -- A
         -- Alpha
                    -- A-NL
                    -- A-DE
         -- Another thing
                    -- A1-NL
                    -- A2-NL
    -- B
         -- Beer
    etc.

    My goals is to put all the lowest level-nodes (A-NL, A-DE, A1-NL, A2-NL) in a list of nodes.

    After I retrieved this node-collection I put it in cache. But retrieving the nodes the first time (so before it's in cache) takes a whole lot of time (+/- over 3 minutes). When it's in cache the site performances okay, but the first time it's awful.

    I retrieve the nodes by

    For Each letterNode As Node In New Node(NODE_ID).Children
         For Each childNode As Node In letterNode.ChildrenAsList
               For Each specificNode As Node In kadoNode.ChildrenAsList
                    returnList.Add(New Cadeau(landKadoNode.Id))
                    Exit For
               Next
         Next
    Next

    So at this time I'm using the NodeFactory.

    Is there a way to speed this up drastically? I've read about Examine but never used it. I thought it is for searching, or will it also help by indexing a big set of nodes?

    Thanks in advance,


    Jeffrey

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    May 03, 2012 @ 17:54
    Jeroen Breuer
    2

    It might be better to use an XPath to get the nodes you want. You could probably do this with uQuery.

    Jeroen

  • Jeffrey Schoemaker 408 posts 2138 karma points MVP 8x c-trib
    May 08, 2012 @ 08:23
    Jeffrey Schoemaker
    0

    Hey Jeroen,

    thanks for the reply, but is a XPath much faster than using the Nodefactory?

    Jeffrey

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    May 08, 2012 @ 08:40
    Hendy Racher
    2

    Hi Jeffrey,

    Yes, XPath should be much quicker, as it'll only inflate the node objects you require in your result set, rather than every node and then checking to see if it belongs in the results.

    HTH,

    Hendy

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    May 08, 2012 @ 09:41
    Chriztian Steinmeier
    1

    If they're regular Umbraco nodes, an XPath like this would be worth trying:

    /root/*[@isDoc]/*[@isDoc]/*[@isDoc]

    - but it can be improved by adding the correct aliases for the doctypes, e.g.:

    /root/Letter/Category/Final

    (obviously replace with the actual doctypes you're using - even if they're all the same)

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft