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?
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.
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
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
It might be better to use an XPath to get the nodes you want. You could probably do this with uQuery.
Jeroen
Hey Jeroen,
thanks for the reply, but is a XPath much faster than using the Nodefactory?
Jeffrey
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
If they're regular Umbraco nodes, an XPath like this would be worth trying:
- but it can be improved by adding the correct aliases for the doctypes, e.g.:
(obviously replace with the actual doctypes you're using - even if they're all the same)
/Chriztian
is working on a reply...