Copied to clipboard

Flag this post as spam?

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


  • Steve Smith 75 posts 158 karma points
    Oct 24, 2012 @ 10:33
    Steve Smith
    0

    Model.NodeById causing errors in umbracoLog table

    Hi all,

    To give some background, we have a large multisite Umbraco (4.7) installation.  At the bottom of each page, there is a footer with a "quick links" area, which provides links to various other nodes on the site (these nodes are selected in the back-office using the uComponents Multi Node Tree Picker).

    We iterate through the list of node IDs stored by the Multi Node Tree Picker, and then use Model.NodeById() to grab the node, and therefore the Url and Name.

    The other day, we noticed the umbracoLog table was getting quite large quite quickly, and most frequently the error being logged was (hundreds of thousands of them) -

    Couldn't find any page with the nodeId = 0. This is most likely caused by the page isn't published!

    Eventually tracked this down to the Model.NodeById() call.  If the node ID you pass is related to a node which has since been deleted or unpublished, it leads to that error being logged in the database.  On some pages, where we found this was the case for maybe 4 or 5 nodes, the umbracoLog database table gets 4 or 5 records added to it every page impression.  

    Since the whole point of Umbraco storing the site in memory as an XML document (to me) was to avoid database access where possible, I'm guessing there must be a performance hit related to this happening.

    So, my question is this - is there a function similar to NodeById(), but checks to see if the node actually exists? 

    Or, are they any alternative methods for grabbing a node from an Id that are safer?  I thought about using XPath, and although this prevents the error being logged, it has a fairly significant performance overhead on our site (which has 1000s of nodes).

    Alternatively, is there some way of turning off this particular log event?

    To compound the problem, it seems that once you've selected the node in the Multi Node Tree Picker, it remains in the XML for the page, even if you republish (doesn't appear in the list in the back-office once deleted, but the Node ID seems to persist).

    I know we can clear out the umbracoLog table, but I'd rather stop the errors being logged in the first place if possible.  Any help would be welcome! 

    Steve.

  • Steve Smith 75 posts 158 karma points
    Oct 24, 2012 @ 10:50
    Steve Smith
    0

    Of course, after for a good couple of hours yesterday evening to find an acceptable work-around for this problem (and failing), I then find a solution myself within 5 minutes of posting here :-)  For benefit of others who might be coming across this problem, here is my solution:

    dynamic linkNode = Model.NodeById(intNodeId);
    if(linkNode.HasValue("Name"))
    {
      <li><a href="@linkNode.Url">@linkNode.Name</a></li>
    }

    if HasValue("Name") is false, it means the node doesn't exist.  And more importantly, the "HasValue" check doesn't cause any errors to be logged.

Please Sign in or register to post replies

Write your reply to:

Draft