]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix admin logs cache caching rounds forever if multiple game servers are ran on the...
authorDrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com>
Mon, 5 Aug 2024 23:13:27 +0000 (16:13 -0700)
committerGitHub <noreply@github.com>
Mon, 5 Aug 2024 23:13:27 +0000 (16:13 -0700)
Content.Server/Administration/Logs/AdminLogManager.Cache.cs

index c194527d826275e828ae558d14c3006b5e42f8db..250d0f7aa345300c42ca9d84d1a6f66c3e2f852f 100644 (file)
@@ -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",
@@ -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);
     }