Copied to clipboard

Flag this post as spam?

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


  • Kyle 24 posts 63 karma points
    Aug 12, 2014 @ 19:26
    Kyle
    0

    Speed issue : Creating league table from 500 nodes

    Hi Guys,

    I'm struggling with speed it's taking 5.83s to load my league table view and I feel that it maybe to do with my method.

    Select all the clubs in the selected division then select all valid results (publised & not postponed/abandoned) then I'm filtering the results set (1500 or so) for the results with the clubs from my clubs list (around 500 nodes) then adding them to list then sorting that list.

    Any help or suggestions would be greatly appreciated.

    See the code below.

    Umbraco V7.1.4

    Thanks, Kyle :)

    @inherits UmbracoTemplatePage
    @using Umbraco.Web.Models
    
    @{
    
    int division;
    var divisionBool = int.TryParse(Model.Content.GetPropertyValue("division").ToString(), out division);
    
    int source;
    var sourceBool = int.TryParse(Model.Content.GetPropertyValue("source").ToString(), out source);
    
    int clubs;
    var clubsBool = int.TryParse(Model.Content.GetPropertyValue("clubs").ToString(), out clubs);
    
    }
    
    @{
    
    
    List<TableFilter> list = new List<TableFilter>();
    
    }
    
    @if (sourceBool == true && divisionBool == true && clubsBool == true)
    {
        //Select all Clubs in divison
        var clubsList = Umbraco.TypedContent(clubs).Children.Where(x => x.GetPropertyValue<int>("division") == division).OrderBy(x => x.GetPropertyValue("Name"));
        //Select all the Results
        var allResults = Umbraco.TypedContent(source).Children.Where(x => x.GetPropertyValue<bool>("publishResult") == true && x.GetPropertyValue<bool>("fixtureAbandoned") == false && x.GetPropertyValue<bool>("fixturePostponed") == false);
        //by date
        var results = allResults.Where(x => Umbraco.TypedContent(x.GetPropertyValue<int>("homeTeam")).GetPropertyValue<int>("division") == division && Umbraco.TypedContent(x.GetPropertyValue<int>("awayTeam")).GetPropertyValue<int>("division") == division).OrderByDescending(x => x.GetPropertyValue<DateTime>("date"));
    
    if (results.Count() > 0)
    {
    //Select the date ready to format
    var latestDate = results.First().GetPropertyValue<DateTime>("Date");
    
    <p class="update-date"> Last Updated: @latestDate.DayOfWeek @latestDate.ToLongDateString()</p>
    }
    
    if (clubsList.Count() > 0 && results.Count() > 0)
    {
        foreach (var item in clubsList)
        {
    
    
            var homeGames = results.Where(x => x.GetPropertyValue<int>("homeTeam") == item.Id);
            var awayGames = results.Where(x => x.GetPropertyValue<int>("awayTeam") == item.Id);
    
            int played = homeGames.Count() + awayGames.Count();
            int homeWin = homeGames.Where(x => x.GetPropertyValue<int>("homeTeamGoals") > x.GetPropertyValue<int>("awayTeamGoals")).Count();
            int homeDraw = homeGames.Where(x => x.GetPropertyValue<int>("homeTeamGoals") == x.GetPropertyValue<int>("awayTeamGoals")).Count();
            int homeLose = homeGames.Where(x => x.GetPropertyValue<int>("homeTeamGoals") < x.GetPropertyValue<int>("awayTeamGoals")).Count();
            int awayWin = awayGames.Where(x => x.GetPropertyValue<int>("awayTeamGoals") > x.GetPropertyValue<int>("homeTeamGoals")).Count();
            int awayDraw = awayGames.Where(x => x.GetPropertyValue<int>("awayTeamGoals") == x.GetPropertyValue<int>("homeTeamGoals")).Count();
            int awayLose = awayGames.Where(x => x.GetPropertyValue<int>("awayTeamGoals") < x.GetPropertyValue<int>("homeTeamGoals")).Count();
            int win = homeWin + awayWin;
            int draw = homeDraw + awayDraw;
            int lose = homeLose + awayLose;
            int goalsFor = homeGames.Sum(x => x.GetPropertyValue<int>("homeTeamGoals")) + awayGames.Sum(x => x.GetPropertyValue<int>("awayTeamGoals"));
            int goalsAgainst = homeGames.Sum(x => x.GetPropertyValue<int>("awayTeamGoals")) + awayGames.Sum(x => x.GetPropertyValue<int>("homeTeamGoals"));
            int goalDifference = goalsFor - goalsAgainst;
            int points = (win * 3) + draw;
            int deductions = item.GetPropertyValue<int>("pointDeductions");
            int totalPoints = points + deductions;
    
            TableFilter filter = new TableFilter();
    
            filter.name = item.Name;
            filter.url = item.Url;
            filter.played = played;
            filter.homeWin = homeWin;
            filter.homeDraw = homeDraw;
            filter.homeLose = homeLose;
            filter.awayWin = awayWin;
            filter.awayDraw = awayDraw;
            filter.awayLose = awayLose;
            filter.win = homeWin + awayWin;
            filter.draw = homeDraw + awayDraw;
            filter.lose = homeLose + awayLose;
            filter.goalsFor = homeGames.Sum(x => x.GetPropertyValue<int>("homeTeamGoals")) + awayGames.Sum(x => x.GetPropertyValue<int>("awayTeamGoals"));
            filter.goalsAgainst = homeGames.Sum(x => x.GetPropertyValue<int>("awayTeamGoals")) + awayGames.Sum(x => x.GetPropertyValue<int>("homeTeamGoals"));
            filter.goalDifference = goalsFor - goalsAgainst;
            filter.points = (win * 3) + draw;
            filter.deductions = item.GetPropertyValue<int>("pointDeductions");
            filter.totalPoints = points + deductions;
            filter.pointDeductionComment = item.GetPropertyValue<String>("pointDeductionComment");
    
            list.Add(filter);
    
        }
        <table class="league-table">
            <tbody>
                <tr>
                    <th>&nbsp;</th>
                    <th class="club">Team</th>
                    <th>Pld</th>
                    <th class="mobile-no">HW</th>
                    <th class="mobile-no">HD</th>
                    <th class="mobile-no">HL</th>
                    <th class="mobile-no">AW</th>
                    <th class="mobile-no">AD</th>
                    <th class="mobile-no">AL</th>
                    <th>W</th>
                    <th>D</th>
                    <th>L</th>
                    <th class="mobile-no">GF</th>
                    <th class="mobile-no">GA</th>
                    <th>GD</th>
                    <th class="points">Pts</th>
                </tr>
    
                @{int i = 1;}
                @foreach (var club in list.OrderByDescending(x => x.totalPoints).ThenByDescending(x => x.goalDifference).ThenByDescending(x => x.goalsFor).ThenBy(x => x.name))
                {
                    <tr>
                        <td>@i</td>
                        <td class="club"><a href="@club.url">@club.name</a></td>
                        <td class="alt">@club.played</td>
                        <td class="mobile-no">@club.homeWin</td>
                        <td class="alt mobile-no">@club.homeDraw</td>
                        <td class="mobile-no">@club.homeLose</td>
                        <td class="alt mobile-no">@club.awayWin</td>
                        <td class="mobile-no">@club.awayDraw</td>
                        <td class="alt mobile-no">@club.awayLose</td>
                        <td class="">@club.win</td>
                        <td class="alt">@club.draw</td>
                        <td class="">@club.lose</td>
                        <td class="alt mobile-no">@club.goalsFor</td>
                        <td class=" mobile-no">@club.goalsAgainst</td>
                        <td class="alt">@club.goalDifference</td>
                        <td class="">
                            @club.totalPoints
                            @if (club.deductions != 0)
                            {
                                <span class="deductions">
                                    <a title="@club.pointDeductionComment">@club.deductions</a>
                                </span>
                            }
                        </td>
                    </tr>
                    i++;
                }
            </tbody>
        </table>
    }
    else
    {
        <p>No results found.</p>
    }
    
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft