Skip to content

Commit

Permalink
v3.18.2 (#419)
Browse files Browse the repository at this point in the history
* Fix an issue that prevented bonuses from being included in 'advanced' score.

* Fix advance bonuses

* Add game cache invalidate on rerank
  • Loading branch information
sei-bstein committed Apr 9, 2024
1 parent 1124a48 commit ad4d932
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/Gameboard.Api/Features/Game/GameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,12 @@ public async Task<ActionResult<UploadedFile>> DeleteImage([FromRoute] string id,
[Authorize(AppConstants.AdminPolicy)]
public async Task Rerank([FromRoute] string id, CancellationToken cancellationToken)
{
AuthorizeAny(
() => Actor.IsDesigner
);
AuthorizeAny(() => Actor.IsDesigner);

await Validate(new Entity { Id = id });
await GameService.ReRank(id);
await _scoreDenormalization.DenormalizeGame(id, cancellationToken);
await _mediator.Publish(new GameCacheInvalidateCommand(id));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using MediatR;

namespace Gameboard.Api.Features.Games;

public record GameCacheInvalidateCommand(string GameId) : INotification;
17 changes: 10 additions & 7 deletions src/Gameboard.Api/Features/Hubs/GameHub/GameHubService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Gameboard.Api.Features.Games;

public interface IGameHubService : INotificationHandler<GameEnrolledPlayersChangeNotification>, INotificationHandler<AppStartupNotification>
public interface IGameHubService : INotificationHandler<GameEnrolledPlayersChangeNotification>, INotificationHandler<AppStartupNotification>, INotificationHandler<GameCacheInvalidateCommand>
{
// invoke functions on clients
Task SendExternalGameChallengesDeployStart(GameStartUpdate state);
Expand Down Expand Up @@ -230,11 +230,14 @@ public async Task Handle(AppStartupNotification appStartupNotification, Cancella
.ToArrayAsync(cancellationToken);

foreach (var game in games)
await UpdateGameIdUserIdsMap(new GameEnrolledPlayersChangeNotification(new GameEnrolledPlayersChangeContext(game.Id, game.RequireSynchronizedStart)));
await UpdateGameIdUserIdsMap(game.Id);
}

public Task Handle(GameCacheInvalidateCommand notification, CancellationToken cancellationToken)
=> UpdateGameIdUserIdsMap(notification.GameId);

public Task Handle(GameEnrolledPlayersChangeNotification notification, CancellationToken cancellationToken)
=> UpdateGameIdUserIdsMap(notification);
=> UpdateGameIdUserIdsMap(notification.Context.GameId);

private IEnumerable<string> GetGameUserIds(string gameId)
{
Expand All @@ -245,21 +248,21 @@ private IEnumerable<string> GetGameUserIds(string gameId)
return userIds;
}

private async Task UpdateGameIdUserIdsMap(GameEnrolledPlayersChangeNotification notification)
private async Task UpdateGameIdUserIdsMap(string gameId)
{
var gameUsers = await _store
.WithNoTracking<Data.Player>()
.Where(p => p.Game.GameEnd != DateTimeOffset.MinValue || p.Game.GameEnd > _now.Get())
.Where(p => p.Game.PlayerMode == PlayerMode.Competition && p.Mode == PlayerMode.Competition)
.Where(p => p.GameId == notification.Context.GameId)
.Where(p => p.GameId == gameId)
.Select(p => p.UserId)
.Distinct()
.ToArrayAsync();

lock (_gameIdUserIdsMap)
{
_gameIdUserIdsMap.TryRemove(notification.Context.GameId, out var existingValue);
_gameIdUserIdsMap.TryAdd(notification.Context.GameId, gameUsers);
_gameIdUserIdsMap.TryRemove(gameId, out var existingValue);
_gameIdUserIdsMap.TryAdd(gameId, gameUsers);
}
}
}

0 comments on commit ad4d932

Please sign in to comment.