Copied to clipboard

Flag this post as spam?

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


  • Eise van der Spoel 10 posts 90 karma points
    Apr 15, 2015 @ 11:59
    Eise van der Spoel
    0

    Slow content loading with IPublishedContent

    Hello :)

    I Have the following code:

    @using umbraco; @using umbraco.MacroEngines; @using Umbraco.Web; @using Umbraco.Core; @inherits umbraco.MacroEngines.DynamicNodeContext @{

    HttpContext.Current.Trace.Write("Start navigatie");
     var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
    
    HttpContext.Current.Trace.Write("Umbracohelper opgehaald");
    var content = umbracoHelper.TypedContent(1071).Children.Where(f => f.IsVisible());
    
    HttpContext.Current.Trace.Write("content opgehaald");
    <ul>
        <li><a href="/">Home</a></li>
    
        @{ 
            HttpContext.Current.Trace.Write("Hoogste foreach");
            foreach(var doc in content)
            {
                <li><a href="">@doc.Name</a>
    
                     @if (doc.Id == 1195)
                    {
                        <ul>
                            @{  
                                HttpContext.Current.Trace.Write("Sub foreach");
                                foreach (var ch in doc.Descendants("Regio"))
                                {
                                    <li><a href="">@ch.Name</a></li>
                                }
                                HttpContext.Current.Trace.Write("Sub foreach klaar");
                            }
                        </ul>
                    }
    
                </li>
            }
            HttpContext.Current.Trace.Write("Hoogste foreach klaar");
        }
    
    </ul>
    

    }

    The last foreach takes about 3 seconds! The first one 1 second. How is this posible? For the second foreach there are around 5000 nodes but only a view will be displayed in the menu.

    Does anyone has some tips?

    Trace:

    umbracoMacro Loading Macro Script Context (file: Navigatie) 1,661313 1,607701 umbracoMacro Loading Macro Script Context (file: Navigatie) 1,661422 0,000108 umbracoMacro Done Loading Macro Script Context (file: Navigatie) 1,661463 0,000041 umbracoMacro Boxing Macro Script MacroContext (file: Navigatie) 1,661495 0,000032 umbracoMacro Done Boxing Macro Script MacroContext (file: Navigatie) 1,661524 0,000029 umbracoMacro Loading Macro Script Model (file: Navigatie) 1,661551 0,000027 umbracoMacro Done Loading Macro Script Model (file: Navigatie) 1,661619 0,000068 umbracoMacro Done Loading Macro Script Context (file: Navigatie) 1,661647 0,000028 umbracoMacro Executing Macro Script (file: Navigatie) 1,661676 0,000029 Start navigatie 1,663897 0,002220 Umbracohelper opgehaald 1,663956 0,000059 content opgehaald 1,664852 0,000897 Hoogste foreach 1,664906 0,000053 Sub foreach 1,689987 0,025082 Sub foreach klaar 5,501504 3,811516 Hoogste foreach klaar 5,501659 0,000155 umbracoMacro Done Executing Macro Script (file: Navigatie) 5,501726 0,000067 End: Executing MacroEngineScript: Navigatie.cshtml 5,501888 0,000161 End: Render Macro: Navigatie, type: Script, cache: 0) 5,501957 0,000069

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 15, 2015 @ 12:33
    Dave Woestenborghs
    0

    Are your "Region" doctypes direct children of your node with Id 1195. If so you can probably speed up things by using Children instead of descendants. Descendants will get all underlying nodes no matter the level. And then will perform the filtering.

    You can probably cache this macro for a long time, so you only have this performance hit on the first time it's rendered.

    Dave

  • Eise van der Spoel 10 posts 90 karma points
    Apr 15, 2015 @ 12:47
    Eise van der Spoel
    0

    The Children of the second level (the second foreach) contains 5000 nodes, using this:

    doc.Children.Where("NodeTypeAlias == \"Regio\"")

    Takes around 7 seconds.

    I am using Cache, but still Umbraco gets very very slow when using a lot of nodes. If a visitor has to wait 10 seconds for a (uncached) page to load it's just slow.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 15, 2015 @ 12:57
    Dave Woestenborghs
    0

    5000 nodes is a lot of children for one node. This is also not workable from a editors point of view.

    Maybe you can structure them in folders.

    Can you try this :

    doc.Children.Where(x => x.DocumentTypeAlias == "Regio")

    This is strongly type, while the code you have uses dynamic. Using dynamics can be a performance hit when used in where clauses.

    Dave

     

  • Eise van der Spoel 10 posts 90 karma points
    Apr 15, 2015 @ 13:02
    Eise van der Spoel
    0

    Yhe, we are working on a solution for that.

    The solution you provide takes 3,250178 seconds. With caching it isn't even thinking about it anymore.

    Some more optimizations are necessary. But it's a step in the right direction.

    Thanks for you support!

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 15, 2015 @ 13:05
    Dave Woestenborghs
    0

    Can I ask what version of Umbraco you are using ? I see you are still using the old razor engine.

    Since Umbraco v4.10 you can use partial view macro's : https://our.umbraco.org/documentation/Reference/Templating/Macros/Partial-View-Macros/

    Dave

     

  • Eise van der Spoel 10 posts 90 karma points
    Apr 15, 2015 @ 14:11
    Eise van der Spoel
    0

    We are currently using Umbraco v6.2.4. As i did some reading i noticed the Razor Macro's are still there for legacy. I switched the script to a partial view macro:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
    var content = Umbraco.TypedContent(1071).Children.Where(f => f.IsVisible());
    <ul>
        <li><a href="/">Home</a></li>
    
        @{ 
            foreach(var doc in content)
            {
                <li><a href="@doc.Url">@doc.Name</a>
    
                     @if (doc.Id == 1195)
                    {
                        <ul>
                            @{  
                                foreach (var ch in doc.Children.Where(x => x.DocumentTypeAlias == "RegioPagina"))
                                {
                                    <li><a href="@ch.Url">@ch.Name</a></li>
                                }
                            }
                        </ul>
                    }
    
                </li>
            }
        }
    
    </ul>
    }
    

    Do you have any more suggestions? :)

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Apr 15, 2015 @ 16:29
Please Sign in or register to post replies

Write your reply to:

Draft