the need for speed

This commit is contained in:
rootdarkarchon
2023-04-29 23:32:54 +02:00
parent de2cd97dbe
commit 3715ca5ce3
8 changed files with 82 additions and 102 deletions

View File

@@ -14,6 +14,7 @@ namespace MareSynchronos.PlayerData.Pairs;
public class Pair
{
private readonly Func<OnlineUserIdentDto, CachedPlayer> _cachedPlayerFactory;
private readonly SemaphoreSlim _creationSemaphore = new(1);
private readonly ILogger<Pair> _logger;
private readonly MareMediator _mediator;
private readonly ServerConfigurationManager _serverConfigurationManager;
@@ -89,19 +90,28 @@ public class Pair
public void CreateCachedPlayer(OnlineUserIdentDto? dto = null)
{
if (dto == null && _onlineUserIdentDto == null)
try
{
CachedPlayer?.Dispose();
CachedPlayer = null;
return;
}
if (dto != null)
{
_onlineUserIdentDto = dto;
}
_creationSemaphore.Wait();
CachedPlayer?.Dispose();
CachedPlayer = _cachedPlayerFactory(_onlineUserIdentDto!);
if (dto == null && _onlineUserIdentDto == null)
{
CachedPlayer?.Dispose();
CachedPlayer = null;
return;
}
if (dto != null)
{
_onlineUserIdentDto = dto;
}
CachedPlayer?.Dispose();
CachedPlayer = _cachedPlayerFactory(_onlineUserIdentDto!);
}
finally
{
_creationSemaphore.Release();
}
}
public string? GetNote()