From: DrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com> Date: Mon, 5 Aug 2024 23:13:27 +0000 (-0700) Subject: Fix admin logs cache caching rounds forever if multiple game servers are ran on the... X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=edd17072ae7becc7a39043d9f31652757c4cc768;p=space-station-14.git Fix admin logs cache caching rounds forever if multiple game servers are ran on the same db (#30687) --- 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); }