I have a contentpicker that allows me to link related content to my current page. However, if the related content is unpublished or deleted, I don't want to see the div that contains links to this content. Currently I am doing a GetXmlNodeById() and checking if there is a nodeName property on the related item.
I can't help but feel that this could be done a little more efficiently, just don't know how:
I've not run tests to confirm this myself, but knowing that umbraco.library calls have more overhead than good xpath statements, here are my thoughts...
If you can avoid calls to the umbraco.library you'll generally have a faster macro. Not that the umbraco library is slow, but if you're trying to get every last drop of performance then the fewer calls the better.
Your alternative would be to go up the content tree from $currentPage and then search for the [@id = $id] entirely in xpath.
If you have a massive content structure to go through this may take longer than the umbraco.library:GetXmlNodeById() call and not be a good option. Though your content tree would need to be truly large.
Thus, there is no firm answer as to which is best. Rather, look at the performance of your specific situation and choose the one better suited to your needs.
Need to check if a node still exists
XSLT masters, can this be done in a better way?
I have a contentpicker that allows me to link related content to my current page. However, if the related content is unpublished or deleted, I don't want to see the div that contains links to this content. Currently I am doing a GetXmlNodeById() and checking if there is a nodeName property on the related item.
I can't help but feel that this could be done a little more efficiently, just don't know how:
What about something like this? Not sure how much more efficient it will be
Dan
I'd do as Dan suggests, but instead of checking for "No published item exist", I'd do a "count($currentItem/error) = 0".
I've not run tests to confirm this myself, but knowing that umbraco.library calls have more overhead than good xpath statements, here are my thoughts...
If you can avoid calls to the umbraco.library you'll generally have a faster macro. Not that the umbraco library is slow, but if you're trying to get every last drop of performance then the fewer calls the better.
Your alternative would be to go up the content tree from $currentPage and then search for the [@id = $id] entirely in xpath.
If you have a massive content structure to go through this may take longer than the umbraco.library:GetXmlNodeById() call and not be a good option. Though your content tree would need to be truly large.
Thus, there is no firm answer as to which is best. Rather, look at the performance of your specific situation and choose the one better suited to your needs.
Let us know what you find out.
cheers,
doug.
And, of course, after you've gotten the best performing macro... think about caching the macro for even better performance.
Adding ?umbDebugShowTrace=true to the url will show you how long each macro takes to run so you can easily do your own A/B tests.
cheers,
doug.
is working on a reply...