diff --git a/Content.Server/Administration/Logs/AdminLogManager.Cache.cs b/Content.Server/Administration/Logs/AdminLogManager.Cache.cs index c194527d82..250d0f7aa3 100644 --- a/Content.Server/Administration/Logs/AdminLogManager.Cache.cs +++ b/Content.Server/Administration/Logs/AdminLogManager.Cache.cs @@ -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> _roundsLogCache = new(MaxRoundsCached); + private readonly Queue _roundsLogCacheQueue = new(); private static readonly Gauge CacheRoundCount = Metrics.CreateGauge( "admin_logs_cache_round_count", @@ -28,19 +29,21 @@ public sealed partial class AdminLogManager // TODO ADMIN LOGS cache previous {MaxRoundsCached} rounds on startup public void CacheNewRound() { - List list; - var oldestRound = _currentRoundId - MaxRoundsCached; + List? list = null; - if (_roundsLogCache.Remove(oldestRound, out var oldestList)) + _roundsLogCacheQueue.Enqueue(_currentRoundId); + if (_roundsLogCacheQueue.Count > MaxRoundsCached) { - list = oldestList; - list.Clear(); - } - else - { - list = new List(LogListInitialSize); + var oldestRound = _roundsLogCacheQueue.Dequeue(); + if (_roundsLogCache.Remove(oldestRound, out var oldestList)) + { + list = oldestList; + list.Clear(); + } } + list ??= new List(LogListInitialSize); + _roundsLogCache.Add(_currentRoundId, list); CacheRoundCount.Set(_roundsLogCache.Count); }