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"; }
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!
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 :)
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:
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;
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.
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.
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
"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');
@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:
+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
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 :)
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
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:
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:
And the subsequent anchor href call:
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:
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
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:
and changed the search to:
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,
rather than the original two plus steps:
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
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.
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
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.
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:
So I googled this and made the following change to the web.config:
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
or all three?!?!?!
HELP!!!!!!
This doesn't make any sense!
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!
How is the macro entered in the page? page content? masterpage?
@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:
Is there something I should know about with doing this?
Thanks for all the help everyone!
Jon
is working on a reply...