From edd17072ae7becc7a39043d9f31652757c4cc768 Mon Sep 17 00:00:00 2001 From: DrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com> Date: Mon, 5 Aug 2024 16:13:27 -0700 Subject: [PATCH] Fix admin logs cache caching rounds forever if multiple game servers are ran on the same db (#30687) --- .../Logs/AdminLogManager.Cache.cs | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) 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); } -- 2.52.0