Skip to content

Commit

Permalink
Fix admin logs cache caching rounds forever if multiple game servers …
Browse files Browse the repository at this point in the history
…are ran on the same db (#30687)
  • Loading branch information
DrSmugleaf authored Aug 5, 2024
1 parent 9bb9e80 commit edd1707
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions Content.Server/Administration/Logs/AdminLogManager.Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public sealed partial class AdminLogManager

// TODO ADMIN LOGS make this thread safe or remove thread safety from the main partial class
private readonly Dictionary<int, List<SharedAdminLog>> _roundsLogCache = new(MaxRoundsCached);
private readonly Queue<int> _roundsLogCacheQueue = new();

private static readonly Gauge CacheRoundCount = Metrics.CreateGauge(
"admin_logs_cache_round_count",
Expand All @@ -28,19 +29,21 @@ public sealed partial class AdminLogManager
// TODO ADMIN LOGS cache previous {MaxRoundsCached} rounds on startup
public void CacheNewRound()
{
List<SharedAdminLog> list;
var oldestRound = _currentRoundId - MaxRoundsCached;
List<SharedAdminLog>? list = null;

if (_roundsLogCache.Remove(oldestRound, out var oldestList))
_roundsLogCacheQueue.Enqueue(_currentRoundId);
if (_roundsLogCacheQueue.Count > MaxRoundsCached)
{
list = oldestList;
list.Clear();
}
else
{
list = new List<SharedAdminLog>(LogListInitialSize);
var oldestRound = _roundsLogCacheQueue.Dequeue();
if (_roundsLogCache.Remove(oldestRound, out var oldestList))
{
list = oldestList;
list.Clear();
}
}

list ??= new List<SharedAdminLog>(LogListInitialSize);

_roundsLogCache.Add(_currentRoundId, list);
CacheRoundCount.Set(_roundsLogCache.Count);
}
Expand Down

0 comments on commit edd1707

Please sign in to comment.