Copied to clipboard

Flag this post as spam?

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


  • Jon R. Humphrey 164 posts 455 karma points c-trib
    Oct 05, 2011 @ 20:14
    Jon R. Humphrey
    0

    +18 Seconds to load?

    Please help ... in dire need of assistance!!!!

    @using System.Xml
    @using System.Xml.Linq
    @using umbraco.MacroEngines
    @inherits DynamicNodeContext
    @functions {
    public static string GetImageCropperUrlFullMedia(string mediaXml, string cropName) {
    string cropUrl = string.Empty;

    XmlDocument xmlDocument = new XmlDocument();
    xmlDocument.LoadXml("" + mediaXml + "");
    XmlNode cropNode = xmlDocument.SelectSingleNode("descendant::crops/crop[@name='"+ cropName +"']");

    if (cropNode != null){
    cropUrl = cropNode.Attributes.GetNamedItem("url").InnerText;
    }
    return cropUrl;
    }
    }
    @{
    var thumb = String.Empty;
    var projectYear = String.Empty;
    var projectClient = String.Empty;
    var projectAuthour= String.Empty;
    }

    <ol id="project_items" class="noBullet horizontal">
    @foreach ( var project in Model.Descendants().Where( "Visible" ) ) {

    var firstGallery = project.DescendantsOrSelf( "stfuGallery" ).First();
    var subGallery = firstGallery.DescendantsOrSelf( 5 ).First();
    var link = ( subGallery.NodeTypeAlias == "stfuGallery" ) ? subGallery.Url : firstGallery.Url;


    if ( project.GetProperty( "projectThumbnailImage" ) != null && project.GetProperty( "projectThumbnailImage" ).Value != "" ) {
    thumb = GetImageCropperUrlFullMedia( project.GetProperty( "projectThumbnailImage" ).Value.ToString(), "GalleryImageThumbnail" );
    } else {
    thumb = "/css/global/no_image_found.png";
    }

    if ( project.GetProperty("projectClient") != null && project.GetProperty("projectClient").Value != "" ) {
    projectClient= project.projectClient.ToString();
    } else {
    projectClient = null;
    }

    if ( project.GetProperty("projectAuthour") != null && project.GetProperty("projectAuthour").Value != "" ) {
    projectAuthour= project.projectAuthour.ToString();
    } else {
    projectAuthour = null;
    }

    var projectFirstLine = (projectAuthour == null ) ? projectClient : projectAuthour;


    if ( project.Parent.Name == Model.Name) {
    <li>
    <header>
    <h6>
    <a href="@link">
    <img src="@thumb" title="View @project.projectTitle" alt="@project.projectTitle" />
    <span>@projectFirstLine <br />@project.projectTitle </span>
    </a>
    </h6>
    </header>
    <article class="opaque">
    <p>@project.shortDescription</p>
    </article>
    </li>
    }
    }
    </ol>

    Currently this code snippet is causing the page the macro is called from up to 18 seconds or more to load and  if I remove the macro call then the page loads in just 2 seconds!

    If you have any questions or need any clarification about anything please post in the comments and I'll be happy to help or explain further!

    Or if you know of a better way to do any part of this code to help it along then please suggest away, I'm open to all thoughts and ideas!

    Thank you in advance!

    Jon

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Oct 05, 2011 @ 22:44
    Dan Diplo
    0

    Your  GetImageCropperUrlFullMedia function will have a lot of overhead as you are creating a new XmlDocument every time and then traversing it which won't be very efficient. If your using Umbraco 4.7.1 you should be able to use Find() method. Something like (untested):

    var crop = node.projectThumbnailImage.Find("@name","GalleryImageThumbnail").url

    Dunno if this will be faster, but it's at least neater :)

  • Jon R. Humphrey 164 posts 455 karma points c-trib
    Oct 06, 2011 @ 00:32
    Jon R. Humphrey
    0

    Dan,

    Thanks for the rapid response! The install is currently running 4.7 not 4.7.1. How do I go about updating it easily?

    Edited: Found this url:

    http://our.umbraco.org/wiki/install-and-setup/upgrading-an-umbraco-installation

    Is this the whole kit and kaboodle or might I just need to update a specific razor engine file?

    Thanks for the help already... again!

    Jon

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Oct 06, 2011 @ 09:43
    Dan Diplo
    0

    Hi Jon,

    Upgrading from 4.7 to 4.7.1 is really simple - it's just a case of downloading a zip file and unziping a couple of folders over the existing files. It's more of a patch release than a full upgrade. So go to http://umbraco.codeplex.com/releases/view/73692 and download the binaries and then read the documentation on that page. In reality all you really need to do is copy the following folders from the zip file over your existing files:

    /bin, /umbraco and /umbraco_client
     
    Good luck!

     

  • Jon R. Humphrey 164 posts 455 karma points c-trib
    Oct 06, 2011 @ 12:54
    Jon R. Humphrey
    0

    Dan,

    I've implemented the suggested updates and everything went through ok. Sadly this did not improve things much...

    However, as I was stepping through the cleaned code again I was able to drop the render the listings to just over 2 seconds when I removed the lines:

        var firstGallery = project.DescendantsOrSelf( "stfuGallery" ).First();
        var subGallery = firstGallery.DescendantsOrSelf( 5 ).First();
        var link = ( subGallery.NodeTypeAlias == "stfuGallery" ) ? subGallery.Url : firstGallery.Url;

    And the subsequent anchor href call:

    <a href="@link">[...]</a>

    Which leads me to wonder if there isn't a better manner to handle the assignment of the listing's link?

    Here is the complete reduced code, including the offending lines:

    @using System.Xml
    @using System.Xml.Linq
    @using umbraco.MacroEngines
    @inherits DynamicNodeContext

    @{
        var thumb = String.Empty;
        var projectYear = String.Empty;
        var projectClient = String.Empty;
        var projectAuthour= String.Empty;
      }

      <ol id="project_items" class="noBullet horizontal">
      @foreach ( var project in Model.Descendants().Where( "Visible" ) ) {

        var firstGallery = project.DescendantsOrSelf( "stfuGallery" ).First();
        var subGallery = firstGallery.DescendantsOrSelf( 5 ).First();
        var link = ( subGallery.NodeTypeAlias == "stfuGallery" ) ? subGallery.Url : firstGallery.Url;

       
        if ( project.GetProperty( "projectThumbnailImage" ) != null && project.GetProperty( "projectThumbnailImage" ).Value != "" ) {
          thumb =  project.projectThumbnailImage.Find("@name","GalleryImageThumbnail").url;
        } else {
          thumb = "/css/global/no_image_found.png";
        }

        if ( project.GetProperty("projectClient") != null && project.GetProperty("projectClient").Value != "" ) {
          projectClient= project.projectClient.ToString();
        } else {
          projectClient = null;
        }
                                                                          
        if ( project.GetProperty("projectAuthour") != null && project.GetProperty("projectAuthour").Value != "" ) {
          projectAuthour= project.projectAuthour.ToString();
        } else {
          projectAuthour = null;
        }
        
        var projectFirstLine = (projectAuthour == null ) ? projectClient : projectAuthour;


        if ( project.Parent.Name == Model.Name) {
          <li>
            <header>
              <h6>
                  <a href="@link">
                  <img src="@thumb" title="View @project.projectTitle" alt="@project.projectTitle" />
                  <span>@projectFirstLine <br />@project.projectTitle </span>
                </a>
              </h6>
            </header>
            <article class="opaque">
              <p>@project.shortDescription</p>
            </article>
          </li>
        }
      }
      </ol>

    If that part of the loop could be refactored in a better way to speed things up then it would be spectacular!

    Thanks for all your help, and anyone else who'd like to jump in here!

    Jon

  • Jon R. Humphrey 164 posts 455 karma points c-trib
    Oct 10, 2011 @ 13:52
    Jon R. Humphrey
    0

    Dan, et al,

    I was able to get this to work for the time being, albeit not in the best manner as I would like, by creating a new property on the project document type called "primaryProjectLink" and setting this to a Content Picker object. I've also removed the offending code snippet of:

        var firstGallery = project.DescendantsOrSelf( "stfuGallery" ).First();
    var subGallery = firstGallery.DescendantsOrSelf( 5 ).First();
    link = ( subGallery.NodeTypeAlias == "stfuGallery" ) ? subGallery.Url : firstGallery.Url;

    and changed the search to:

    if ( project.GetProperty( "primaryProjectLink" ) != null && project.GetProperty( "primaryProjectLink" ).Value != "" ) {
    projectPrimaryUrl = project.NodeById( project.primaryProjectLink ).Url;
    } else {
    projectPrimaryUrl = null;
    }

    var link = (projectPrimaryUrl == null ) ? project.DescendantsOrSelf( "stfuGallery" ).First().Url : projectPrimaryUrl;

    Which has dropped the page load from up to and over 18seconds to just above 10?

    The issue with this is that the client now has to follow a three plus step process,

    1. Create project
    2. Create gallery and/or sub-gallery
    3. Go back to the project and manually choose the link

    rather than the original two plus steps:

    1. Create project
    2. Create gallery and/or sub-gallery

    I really would like to know why the overhead on the recursive search in the original code for sub-gallery is so high?

    Anyone got any thoughts on this which would allow me to go back to the original two step process over the three?

    Thanks for any and all help on this!

    Jon

     

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Oct 10, 2011 @ 15:04
    Dan Diplo
    0

    Hi Jon,

    Not ignoring you, but it's hard to replicate your set-up to understand what the problem might be. If I get time I'll try and look, but can't promise.

    One quick "fix" would be to simply add caching to your Umbraco - after the first load it should then be almost instantaneous.

  • Jon R. Humphrey 164 posts 455 karma points c-trib
    Oct 10, 2011 @ 15:48
    Jon R. Humphrey
    0

    Dan,

    Thanks, would never think that! If you're half as busy as I am then I feel your pain!

    In response, I have done exactly as you stated and set a 900 second cache on the macro!

    Everything is very good now but I would still like to determine how I could speed the whole process up again as this is a situation where you really want to KISS the client as much as possible! ;-)

    If you're interested, and have a spare nanosecond, drop me a line and I'll show you the server if you'd like.

    Thanks again for all the help!

    Jon

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Oct 10, 2011 @ 16:17
    Dan Diplo
    0

    OK, still at work ATM, but will check back later.

    Just one point about cacheing - there is no harm in Umbraco setting the cache period as large as possible since the cache is automatically cleared whenever a page is published. So I always set it really high, as whenever a change is made the cache is cleared and the content regenerated anyway.

  • Jon R. Humphrey 164 posts 455 karma points c-trib
    Oct 11, 2011 @ 19:57
    Jon R. Humphrey
    0

    Right, major issue!

    I updated the files to the 4.7.1 version, made the changes as stated above and now when I go into the BackOffice I can't always edit and save my documents?

    I can make a change, press the save or save & publich (depending on where I am) and the page refreshes but then can jump to another node or throw an error?

    The reported error was:

    Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

    Source Error:

    [No relevant source lines]


    Source File: c:\windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\157e449c\11ce3ec1\App_Web_republish.aspx.10695ae8.6kv5qja4.0.cs Line: 0

    Stack Trace:

    [HttpException (0x80004005): Unable to validate data.]
    System.Web.Configuration.MachineKeySection.GetDecodedData(Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Int32& dataLength) +329
    System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +145

    [ViewStateException: Invalid viewstate.
    Client IP: 81.149.123.40
    Port: 38862
    Referer: http://architecture.stufish.com/umbraco/dialogs/republish.aspx?rnd=95.1&rndo=2.4
    Path: /umbraco/dialogs/republish.aspx
    User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1
    ViewState: /wEPDwUKMTk4ODM4NTgzOQ9kFgJmD2QWAgIDEGRkFgICAw9kFgICAQ9kFgJmDw8WAh4EVGV4dAUVUmVwdWJsaXNoIGVudGlyZSBzaXRlZGRkyjYBtJF5A4izleAhvyzVoEublyMEykQVnR/PAuNNFzU=]

    [HttpException (0x80004005): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.]
    System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +198
    System.Web.UI.ViewStateException.ThrowMacValidationError(Exception inner, String persistedState) +14
    System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +255
    System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState) +4
    System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) +37
    System.Web.UI.HiddenFieldPageStatePersister.Load() +241
    System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +106
    System.Web.UI.Page.LoadAllState() +43
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +8431
    System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +253
    System.Web.UI.Page.ProcessRequest() +78
    System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
    System.Web.UI.Page.ProcessRequest(HttpContext context) +49
    ASP.umbraco_dialogs_republish_aspx.ProcessRequest(HttpContext context) in c:\windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\157e449c\11ce3ec1\App_Web_republish.aspx.10695ae8.6kv5qja4.0.cs:0
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

    So I googled this and made the following change to the web.config:

    <!--<pages enableEventValidation="false">-->
    <pages enableEventValidation="false" viewStateEncryptionMode="Never" enableViewStateMac="false">

    Where the original line is commented out.

    Now I'm no longer getting the MAC error but I'm getting the whole jump/refresh/no save bug?

    If I use Chrome DevTools or Firebug to look at the errors now I'm getting the following:

    "NetworkError: 500 Internal Server Error - http://architecture.stufish.com/WebResource.axd?d=6brLslsLt7Mbfh0u25kePw2&t=634472935579796250"

    or

    "NetworkError: 404 Not Found - http://architecture.stufish.com/ScriptResource.axd?d=dWGQIBnOYq3gBQ132xwiOkT8yZvVUXWKu2-4cJn7aK1nkSRHTVm0vvTQQjNG2Cfnzehz_mIfy6XE0EbNFGjmJ3dXkbhwZ6PDSXte-H6P4vI1&t=16ab2387"

    or even

    Sys.WebForms is undefined
    error source line: [Break On This Error] Sys.WebForms.PageRequestManager._initi..., 'form1', [], [], [], 90, 'ctl00');

    or all three?!?!?!

    HELP!!!!!!

    This doesn't make any sense!

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Oct 11, 2011 @ 21:26
    Dan Diplo
    0

    I've heard you can get similar errors if you haven't got enough memory on your server? Can you restart the app pool in IIS?

    Also, seen this thread? http://our.umbraco.org/forum/core/general/6722-Validation-of-viewstate-MAC-failed

    I'd make sure your web.config is like the one in the 4.7.1. download, too. Maybe compare it with yours.

    Other than that, not sure!


  • Rik Helsen 670 posts 873 karma points
    Oct 12, 2011 @ 11:24
    Rik Helsen
    0

    How is the macro entered in the page? page content? masterpage?

  • Jon R. Humphrey 164 posts 455 karma points c-trib
    Oct 12, 2011 @ 14:56
    Jon R. Humphrey
    0

    @Dan, it seems with all the to and fro-ing and overwriting and updating things seem to have calmed down? I did generate and enter the MAC code, as well as put the updated <page> attribute/value key pairs into the web.config. Let's keep the proverbial fingers crossed for now as the testing both myself and the client have done seems to be working! Thanks again for all your help, maybe someday I can buy you a pint or two to say thanks!

    @Rik, the macro is placed inside a child.master placeholder control as such:

    <%@ Master Language="C#" MasterPageFile="~/masterpages/stfuMaster.master" AutoEventWireup="true" %>

    <asp:content ContentPlaceHolderId="headContent" runat="server">
    <!-- Nothing Here -->
    </asp:content>

    <asp:Content ContentPlaceHolderID="bodyContent" runat="server">
    <article class="projects_listing" id="thumbs">
    <umbraco:Macro Alias="ThumbnailProjectListing" runat="server"/>
    </article>
    </asp:Content>

    <asp:content ContentPlaceHolderId="codeContent" runat="server">
    <!-- Nothing Here -->
    </asp:content>

    Is there something I should know about with doing this?

    Thanks for all the help everyone!
    Jon

Please Sign in or register to post replies

Write your reply to:

Draft