BenFradet/RiotSharp

Optimizing obtaining most played champions in last 100 games

hermderger opened this issue · 1 comments

Is there a more efficient way to obtain the top 6 most played champions of a summoner using their Summoner Name and Region from their last 100 games?

Here is what I am currently using but it's very slow:

List<int> playedChampionIds = new List<int>();
summoner = api.Summoner.GetSummonerByNameAsync(selectedSpecificRegion, name).Result;
var matchListOfSummoner = api.Match.GetMatchListAsync(selectedBroadRegion, summoner.Puuid, null, 100).Result;
foreach (var m in matchListOfSummoner)
{
    var matchData = api.Match.GetMatchAsync(selectedBroadRegion, m).Result;
    var summonerMatchData = matchData.Info.Participants.FirstOrDefault(p => p.SummonerId == summoner.Id);
    if (summonerMatchData != null)
    {
        playedChampionIds.Add(summonerMatchData.ChampionId);
    }
}          

var mostPlayed = (from c in playedChampionIds
                group c by c into grp
                orderby grp.Count() descending
                select grp.Key).Take(6);

Based on available endpoints there is no more efficient way.
You might want to go for an asynchronous approach. This could increase performance for the stake of much more complicated handling.
If you want to get the last 100 ranked games you should add those filters in the matchlist request.