Copied to clipboard

Flag this post as spam?

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


  • Chizzl 36 posts 107 karma points
    Sep 22, 2011 @ 20:48
    Chizzl
    0

    Razor script - page load time unacceptable

    Hi,

    I need to display some statistics of member’s involved in acting and/or directing plays in descending order. Actors/Directors (=members) are related to a play via the uComponents autocomplete datatype.

    I use the code below to display statistical data, but it takes a looooong time to load the page.  Does anyone have any tips on how to improve the performance of the script below? The time it needs to load at this moment is unacceptable, which makes it impossible to launch another great umbraco project to the www.

    @inherits umbraco.MacroEngines.DynamicNodeContext  
    @using umbraco.cms.businesslogic.member 
    @using umbraco.MacroEngines

    @{
                int actor_member = 0;
               
                <div class="statistics">
                            <div class="heading">Name</div>
                            <div class="heading">Actor performance(s)</div>
                            <div class="heading">Director performances</div>
                            <div class="heading">Total performances</div>
                </div>
               
                var members = Member.GetAll;
                var i = Member.GetAll.Count();
                var j = 0;
                int[] PlayerArray = new int[i];
                int[] PlayerArray1 = new int[i];
                int[] PlayerArray2 = new int[i];
                int[] PlayerArray3 = new int[i];
               
                foreach (var item in members) {
                            try  {         
                                        var member = item.Text;
                                        PlayerArray[j] = (int)item.Id;
                                        Page.act_member = member;
                                        var actor = @RenderPage("ActorStatistics.cshtml").ToString();
                                        PlayerArray1[j] = Convert.ToInt32(actor);
                                        Page.director = member;
                                        var director = @RenderPage("DirectorStatistics.cshtml").ToString();
                                        PlayerArray2[j] = Convert.ToInt32(director);
                                        var tot = Convert.ToInt32(actor) + Convert.ToInt32(director);
                                        PlayerArray3[j] = tot;
                            } 
                            catch  {   
                            }
                            j++;
                }
               
                //sort arrays based on total performance
                int temp;
                for(i=1;i<PlayerArray3.Length-1;i++) {
                            for(j=0;j<PlayerArray3.Length-i;j++) {
                                        if(PlayerArray3[j] < PlayerArray3[j+1]) {
                                                    temp = PlayerArray3[j];
                                                    PlayerArray3[j] = PlayerArray3[j+1];
                                                    PlayerArray3[j+1] = temp;
                                                   
                                                    temp = PlayerArray2[j];
                                                    PlayerArray2[j] = PlayerArray2[j+1];
                                                    PlayerArray2[j+1] = temp;
                                                   
                                                    temp = PlayerArray1[j];
                                                    PlayerArray1[j] = PlayerArray1[j+1];
                                                    PlayerArray1[j+1] = temp;
                                                   
                                                    temp = PlayerArray[j];
                                                    PlayerArray[j] = PlayerArray[j+1];
                                                    PlayerArray[j+1] = temp;
               
                                        }
               
                            }
                }
               
                for (int c=0;c<=PlayerArray.Length-1;c++) {
               
                            Member m = new Member(Convert.ToInt32(PlayerArray[c]));
                            <div class="statistics">
                                        <div><a href="/statistieken/[email protected]">@m.Text</a></div>
                                        <div class="centering">@PlayerArray1[c]</div>
                                        <div class="centering">@PlayerArray2[c]</div>
                                        <div class="centering">@PlayerArray3[c]</div>
                            </div>
                }            
    }

     

    The above razor calls two more razors to get acting / directing experience. The first one is listed below.

     

    @inherits umbraco.MacroEngines.DynamicNodeContext  
    @using umbraco.cms.businesslogic.member 
    @using umbraco.MacroEngines

    @{
                dynamic node = new DynamicNode(1096);
                umbraco.MacroEngines.DynamicNodeList list = node.Descendants("voorstelling");
                var orderedlist = list.Items.OrderByDescending(x => x.CreateDate);   
               
                var param = @Page.act_member;
                var i = 0;
               
                foreach(dynamic page in orderedlist) {
               
                            if (page.acteurs.ToString() != string.Empty) {
                                        var tokenSeperatedList = page.acteurs.ToString().Split(',');
                                       
                                        foreach (var item in tokenSeperatedList) {
                                       
                                                    if (item.ToString() != string.Empty){
                                                                try {
                                                                            var a_member = new Member(Convert.ToInt32(item)).Text;
                                                                            if(a_member == param) {
                                                                            i++;
                                                                }
                                                                catch {
                                                                }
                                                    }
                                        }
                            }
                }
               
                @i
    }

     

  • Chizzl 36 posts 107 karma points
    Sep 23, 2011 @ 23:00
    Chizzl
    0

    No razor king or Umbraco hero that can help me out on this one?

Please Sign in or register to post replies

Write your reply to:

Draft