I need to find the start node of my forum, I have no idea where in the tree it could be and users can move it - But I need to get hold it. Currently I'm doing this...
var forumRoot = Node.GetNodeByXpath("//Forum");
But I know the dreaded double slash isn't very efficient on large sites! Looking at you XSLT nutters lovely people to help me with some tips ;)
Since you know you want to return the first match, I wonder if the following would help (I'd be interested to know) ?
var forumRoot =Node.GetNodeByXpath("//Forum[1]");
Alternativily (if it really is slow) how about caching the result in application scope with an event hander such that if the Forum node moves to wipe the app scope ?
@Hendy - Thanks, I have added that - I am in fact caching the query once I have it, was just looking for the best way any time it has to make a call to that method :)
The [1] should speed it up as the parser should stop once its got a match rather than getting all Forums and then pruning off the first one.
Might be better still to just go from the root /root/descendant::Forum[1] at least that would start from the top of the tree (the forum should not be too deep right?). Not sure if it would help much but I'd be interested to see what it does for performance?
More Efficient Way Of Doing This
I need to find the start node of my forum, I have no idea where in the tree it could be and users can move it - But I need to get hold it. Currently I'm doing this...
But I know the dreaded double slash isn't very efficient on large sites! Looking at you XSLT nutters lovely people to help me with some tips ;)
Thanks in advance
I don't know of a better way, but maybe this topic can help you: http://our.umbraco.org/forum/developers/api-questions/18933-Query-multiple-websites. It shows a lot of ways how you can query the Umbraco xml structure. Maybe you find something useful.
Jeroen
Hi Lee,
Since you know you want to return the first match, I wonder if the following would help (I'd be interested to know) ?
Alternativily (if it really is slow) how about caching the result in application scope with an event hander such that if the Forum node moves to wipe the app scope ?
HTH,
Hendy
@Jeroen - Thanks for the link
@Hendy - Thanks, I have added that - I am in fact caching the query once I have it, was just looking for the best way any time it has to make a call to that method :)
How about using an event handler to detect a move and updating your cached location?
Like the idea of storing its position for speed.
The [1] should speed it up as the parser should stop once its got a match rather than getting all Forums and then pruning off the first one.
Might be better still to just go from the root /root/descendant::Forum[1] at least that would start from the top of the tree (the forum should not be too deep right?). Not sure if it would help much but I'd be interested to see what it does for performance?
Pete
Lee,
what about setting a property on the root node that refers to the Forum node? This way the forum can be moved around.
Another way is to get it by the nodeTypeAlias although I'm not sure this is the fastest way.
Rgds,
David
is working on a reply...