Skip to content

Commit

Permalink
webapi: fix leaderboard (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
or2e authored Jul 17, 2024
1 parent ad5f606 commit 8bef2a7
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/Application/Characters/Queries/GetLeaderboardQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ public async Task<Result<IList<CharacterPublicViewModel>>> Handle(GetLeaderboard
{
// Todo: use DistinctBy here when EfCore implements it (does not work for now: https://github.com/dotnet/efcore/issues/27470 )
var topRatedCharactersByRegion = await _db.Characters
.OrderByDescending(c => c.Rating.CompetitiveValue)
.Where(c => (req.Region == null || req.Region == c.User!.Region)
&& (req.CharacterClass == null || req.CharacterClass == c.Class))
.Take(500)
.ProjectTo<CharacterPublicViewModel>(_mapper.ConfigurationProvider)
.ToArrayAsync(cancellationToken);
.Include(c => c.User)
.OrderByDescending(c => c.Rating.CompetitiveValue)
.Where(c => (req.Region == null || req.Region == c.User!.Region)
&& (req.CharacterClass == null || req.CharacterClass == c.Class))
.Take(500)
.ProjectTo<CharacterPublicViewModel>(_mapper.ConfigurationProvider)
.ToArrayAsync(cancellationToken);

IList<CharacterPublicViewModel> data = topRatedCharactersByRegion.DistinctBy(c => c.User).Take(50).ToList();
IList<CharacterPublicViewModel> data = topRatedCharactersByRegion.DistinctBy(c => c.User.Id).Take(50).ToList();

var cacheOptions = new MemoryCacheEntryOptions()
.SetAbsoluteExpiration(TimeSpan.FromMinutes(1));
Expand Down

0 comments on commit 8bef2a7

Please sign in to comment.