]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix "Next" never sending admin logs for rounds outside the cache, show a round's...
authorDrSmugleaf <DrSmugleaf@users.noreply.github.com>
Wed, 17 May 2023 11:04:28 +0000 (04:04 -0700)
committerGitHub <noreply@github.com>
Wed, 17 May 2023 11:04:28 +0000 (06:04 -0500)
* Fix next never sending logs for rounds outside the cache

* Show round's total log count on the ui

* Disable next button when waiting for a next response

* Cleanup AdminLogsEui.CurrentRoundId

* Fix popout window width

Content.Client/Administration/UI/Logs/AdminLogsControl.xaml.cs
Content.Client/Administration/UI/Logs/AdminLogsEui.cs
Content.Client/Administration/UI/Logs/AdminLogsWindow.xaml
Content.Server/Administration/Logs/AdminLogManager.cs
Content.Server/Administration/Logs/AdminLogsEui.cs
Content.Server/Administration/Logs/IAdminLogManager.cs
Content.Server/Database/ServerDbBase.cs
Content.Server/Database/ServerDbManager.cs
Content.Shared/Administration/Logs/AdminLogsEuiState.cs
Resources/Locale/en-US/administration/ui/admin-logs.ftl

index d7412625f619f2a720355595ab7c4fb42b67416e..665b8eced020890051e9be71d68febd734c26bea 100644 (file)
@@ -54,6 +54,7 @@ public sealed partial class AdminLogsControl : Control
     public string Search => LogSearch.Text;
     private int ShownLogs { get; set; }
     private int TotalLogs { get; set; }
+    private int RoundLogs { get; set; }
     public bool IncludeNonPlayerLogs { get; set; }
 
     public HashSet<LogType> SelectedTypes { get; } = new();
@@ -485,7 +486,7 @@ public sealed partial class AdminLogsControl : Control
         AddLogs(logs);
     }
 
-    private void UpdateCount(int? shown = null, int? total = null)
+    public void UpdateCount(int? shown = null, int? total = null, int? round = null)
     {
         if (shown != null)
         {
@@ -497,7 +498,15 @@ public sealed partial class AdminLogsControl : Control
             TotalLogs = total.Value;
         }
 
-        Count.Text = Loc.GetString("admin-logs-count", ("showing", ShownLogs), ("total", TotalLogs));
+        if (round != null)
+        {
+            RoundLogs = round.Value;
+        }
+
+        Count.Text = Loc.GetString(
+            "admin-logs-count",
+            ("showing", ShownLogs), ("total", TotalLogs), ("round", RoundLogs)
+        );
     }
 
     protected override void Dispose(bool disposing)
index 0a1982ae0a94eb5a7af1b2e5fa9113256d170c53..41eafe7978c9e87291a0e879c021cbfe0aca5719 100644 (file)
@@ -70,6 +70,7 @@ public sealed class AdminLogsEui : BaseEui
 
     private void NextLogs()
     {
+        LogsControl.NextButton.Disabled = true;
         var request = new NextLogsRequest();
         SendMessage(request);
     }
@@ -88,7 +89,7 @@ public sealed class AdminLogsEui : BaseEui
             Maximized = false,
             Title = "Admin Logs",
             Monitor = monitor,
-            Width = 1000,
+            Width = 1100,
             Height = 400
         });
 
@@ -117,6 +118,7 @@ public sealed class AdminLogsEui : BaseEui
 
         LogsControl.SetCurrentRound(s.RoundId);
         LogsControl.SetPlayers(s.Players);
+        LogsControl.UpdateCount(round: s.RoundLogs);
 
         if (!FirstState)
         {
index 84e6866831d69f81369d00c3f7361719a3d6b35d..be3d90aefc24385fc5a5bcc4b1dccb57704dd22a 100644 (file)
@@ -1,6 +1,6 @@
 <DefaultWindow xmlns="https://spacestation14.io"
             xmlns:logs="clr-namespace:Content.Client.Administration.UI.Logs"
             Title="{Loc admin-logs-title}"
-            SetSize="1000 400">
+            SetSize="1100 400">
     <logs:AdminLogsControl Name="Logs" Access="Public"/>
 </DefaultWindow>
index fe0c3fe24e19c95da5693c0da7ad9d25dc901c44..c2ecea57a94b07ad4ba9d14c0c22fbc9e310ad49 100644 (file)
@@ -374,4 +374,9 @@ public sealed partial class AdminLogManager : SharedAdminLogManager, IAdminLogMa
     {
         return Round(_currentRoundId);
     }
+
+    public Task<int> CountLogs(int round)
+    {
+        return _db.CountAdminLogs(round);
+    }
 }
index 48c76205e64270cfd77cddc744d55b7132608aec..fe032d33cc00df17a593ed47b7e64a227a9654c4 100644 (file)
@@ -29,10 +29,11 @@ public sealed class AdminLogsEui : BaseEui
     private int _clientBatchSize;
     private bool _isLoading = true;
     private readonly Dictionary<Guid, string> _players = new();
+    private int _roundLogs;
     private CancellationTokenSource _logSendCancellation = new();
     private LogFilter _filter;
 
-    private DefaultObjectPool<List<SharedAdminLog>> _adminLogListPool =
+    private readonly DefaultObjectPool<List<SharedAdminLog>> _adminLogListPool =
         new(new ListPolicy<SharedAdminLog>());
 
     public AdminLogsEui()
@@ -50,7 +51,7 @@ public sealed class AdminLogsEui : BaseEui
         };
     }
 
-    public int CurrentRoundId => EntitySystem.Get<GameTicker>().RoundId;
+    private int CurrentRoundId => EntitySystem.Get<GameTicker>().RoundId;
 
     public override async void Opened()
     {
@@ -58,8 +59,8 @@ public sealed class AdminLogsEui : BaseEui
 
         _adminManager.OnPermsChanged += OnPermsChanged;
 
-        var roundId = _filter.Round ?? EntitySystem.Get<GameTicker>().RoundId;
-        LoadFromDb(roundId);
+        var roundId = _filter.Round ?? CurrentRoundId;
+        await LoadFromDb(roundId);
     }
 
     private void ClientBatchSizeChanged(int value)
@@ -79,13 +80,13 @@ public sealed class AdminLogsEui : BaseEui
     {
         if (_isLoading)
         {
-            return new AdminLogsEuiState(CurrentRoundId, new Dictionary<Guid, string>())
+            return new AdminLogsEuiState(CurrentRoundId, new Dictionary<Guid, string>(), 0)
             {
                 IsLoading = true
             };
         }
 
-        var state = new AdminLogsEuiState(CurrentRoundId, _players);
+        var state = new AdminLogsEuiState(CurrentRoundId, _players, _roundLogs);
 
         return state;
     }
@@ -120,12 +121,12 @@ public sealed class AdminLogsEui : BaseEui
                     AnyPlayers = request.AnyPlayers,
                     AllPlayers = request.AllPlayers,
                     IncludeNonPlayers = request.IncludeNonPlayers,
-                    LastLogId = 0,
+                    LastLogId = null,
                     Limit = _clientBatchSize
                 };
 
-                var roundId = _filter.Round ??= EntitySystem.Get<GameTicker>().RoundId;
-                LoadFromDb(roundId);
+                var roundId = _filter.Round ??= CurrentRoundId;
+                await LoadFromDb(roundId);
 
                 SendLogs(true);
                 break;
@@ -192,13 +193,16 @@ public sealed class AdminLogsEui : BaseEui
         _logSendCancellation.Dispose();
     }
 
-    private async void LoadFromDb(int roundId)
+    private async Task LoadFromDb(int roundId)
     {
         _isLoading = true;
         StateDirty();
 
-        var round = await Task.Run(() => _adminLogs.Round(roundId));
-        var players = round.Players
+        var round = _adminLogs.Round(roundId);
+        var count = _adminLogs.CountLogs(roundId);
+        await Task.WhenAll(round, count);
+
+        var players = (await round).Players
             .ToDictionary(player => player.UserId, player => player.LastSeenUserName);
 
         _players.Clear();
@@ -208,6 +212,8 @@ public sealed class AdminLogsEui : BaseEui
             _players.Add(id, name);
         }
 
+        _roundLogs = await count;
+
         _isLoading = false;
         StateDirty();
     }
index ecb8184dc099498fc48b93d42a410f30817a38dc..90021e9a36ce80f6315d63b7d6d8c339803b9874 100644 (file)
@@ -23,4 +23,5 @@ public interface IAdminLogManager : ISharedAdminLogManager
     IAsyncEnumerable<string> CurrentRoundMessages(LogFilter? filter = null);
     IAsyncEnumerable<JsonDocument> CurrentRoundJson(LogFilter? filter = null);
     Task<Round> CurrentRound();
+    Task<int> CountLogs(int round);
 }
index 96fddf9a40cf9d5d1cbfeaf5161db48836a90f78..de7beeca49bd7ae3c12f93d9fc5d3d6a12292e8a 100644 (file)
@@ -794,8 +794,8 @@ INSERT INTO player_round (players_id, rounds_id) VALUES ({players[player]}, {id}
             {
                 query = filter.DateOrder switch
                 {
-                    DateOrder.Ascending => query.Where(log => log.Id < filter.LastLogId),
-                    DateOrder.Descending => query.Where(log => log.Id > filter.LastLogId),
+                    DateOrder.Ascending => query.Where(log => log.Id > filter.LastLogId),
+                    DateOrder.Descending => query.Where(log => log.Id < filter.LastLogId),
                     _ => throw new ArgumentOutOfRangeException(nameof(filter),
                         $"Unknown {nameof(DateOrder)} value {filter.DateOrder}")
                 };
@@ -862,6 +862,12 @@ INSERT INTO player_round (players_id, rounds_id) VALUES ({players[player]}, {id}
             }
         }
 
+        public async Task<int> CountAdminLogs(int round)
+        {
+            await using var db = await GetDb();
+            return await db.DbContext.AdminLog.CountAsync(log => log.RoundId == round);
+        }
+
         #endregion
 
         #region Whitelist
index 0190013a8e4bdb14a88166099b42ad2430982478..5dde449b583c719646f75cfe665c0369522c2ee5 100644 (file)
@@ -205,6 +205,7 @@ namespace Content.Server.Database
         IAsyncEnumerable<string> GetAdminLogMessages(LogFilter? filter = null);
         IAsyncEnumerable<SharedAdminLog> GetAdminLogs(LogFilter? filter = null);
         IAsyncEnumerable<JsonDocument> GetAdminLogsJson(LogFilter? filter = null);
+        Task<int> CountAdminLogs(int round);
 
         #endregion
 
@@ -588,6 +589,12 @@ namespace Content.Server.Database
             return _db.GetAdminLogsJson(filter);
         }
 
+        public Task<int> CountAdminLogs(int round)
+        {
+            DbReadOpsMetric.Inc();
+            return _db.CountAdminLogs(round);
+        }
+
         public Task<bool> GetWhitelistStatusAsync(NetUserId player)
         {
             DbReadOpsMetric.Inc();
index 6e4d439c3226725e37cdfb2c3fb983a817690785..fa94fd0b45ea467b6007d92c215862f64a6a8a5d 100644 (file)
@@ -7,10 +7,11 @@ namespace Content.Shared.Administration.Logs;
 [Serializable, NetSerializable]
 public sealed class AdminLogsEuiState : EuiStateBase
 {
-    public AdminLogsEuiState(int roundId, Dictionary<Guid, string> players)
+    public AdminLogsEuiState(int roundId, Dictionary<Guid, string> players, int roundLogs)
     {
         RoundId = roundId;
         Players = players;
+        RoundLogs = roundLogs;
     }
 
     public bool IsLoading { get; set; }
@@ -18,6 +19,8 @@ public sealed class AdminLogsEuiState : EuiStateBase
     public int RoundId { get; }
 
     public Dictionary<Guid, string> Players { get; }
+
+    public int RoundLogs { get; }
 }
 
 public static class AdminLogsEuiMsg
index 457048ff5614f6a4e26b8ef35bfbbe9d05fd9a32..549e9587d7f6ded084398b5bd0fae5db31c1957b 100644 (file)
@@ -1,5 +1,5 @@
 admin-logs-title = Admin Logs Panel
-admin-logs-count = Showing {$showing}/{$total}
+admin-logs-count = Showing {$showing}/{$total} of {$round}
 admin-logs-pop-out = Pop Out
 
 # Round