From: DrSmugleaf Date: Wed, 17 May 2023 11:04:28 +0000 (-0700) Subject: Fix "Next" never sending admin logs for rounds outside the cache, show a round's... X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=b5fe408baf523c7b942cf5721d40895fd374854a;p=space-station-14.git Fix "Next" never sending admin logs for rounds outside the cache, show a round's total logs on the UI (#16531) * 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 --- diff --git a/Content.Client/Administration/UI/Logs/AdminLogsControl.xaml.cs b/Content.Client/Administration/UI/Logs/AdminLogsControl.xaml.cs index d7412625f6..665b8eced0 100644 --- a/Content.Client/Administration/UI/Logs/AdminLogsControl.xaml.cs +++ b/Content.Client/Administration/UI/Logs/AdminLogsControl.xaml.cs @@ -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 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) diff --git a/Content.Client/Administration/UI/Logs/AdminLogsEui.cs b/Content.Client/Administration/UI/Logs/AdminLogsEui.cs index 0a1982ae0a..41eafe7978 100644 --- a/Content.Client/Administration/UI/Logs/AdminLogsEui.cs +++ b/Content.Client/Administration/UI/Logs/AdminLogsEui.cs @@ -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) { diff --git a/Content.Client/Administration/UI/Logs/AdminLogsWindow.xaml b/Content.Client/Administration/UI/Logs/AdminLogsWindow.xaml index 84e6866831..be3d90aefc 100644 --- a/Content.Client/Administration/UI/Logs/AdminLogsWindow.xaml +++ b/Content.Client/Administration/UI/Logs/AdminLogsWindow.xaml @@ -1,6 +1,6 @@  + SetSize="1100 400"> diff --git a/Content.Server/Administration/Logs/AdminLogManager.cs b/Content.Server/Administration/Logs/AdminLogManager.cs index fe0c3fe24e..c2ecea57a9 100644 --- a/Content.Server/Administration/Logs/AdminLogManager.cs +++ b/Content.Server/Administration/Logs/AdminLogManager.cs @@ -374,4 +374,9 @@ public sealed partial class AdminLogManager : SharedAdminLogManager, IAdminLogMa { return Round(_currentRoundId); } + + public Task CountLogs(int round) + { + return _db.CountAdminLogs(round); + } } diff --git a/Content.Server/Administration/Logs/AdminLogsEui.cs b/Content.Server/Administration/Logs/AdminLogsEui.cs index 48c76205e6..fe032d33cc 100644 --- a/Content.Server/Administration/Logs/AdminLogsEui.cs +++ b/Content.Server/Administration/Logs/AdminLogsEui.cs @@ -29,10 +29,11 @@ public sealed class AdminLogsEui : BaseEui private int _clientBatchSize; private bool _isLoading = true; private readonly Dictionary _players = new(); + private int _roundLogs; private CancellationTokenSource _logSendCancellation = new(); private LogFilter _filter; - private DefaultObjectPool> _adminLogListPool = + private readonly DefaultObjectPool> _adminLogListPool = new(new ListPolicy()); public AdminLogsEui() @@ -50,7 +51,7 @@ public sealed class AdminLogsEui : BaseEui }; } - public int CurrentRoundId => EntitySystem.Get().RoundId; + private int CurrentRoundId => EntitySystem.Get().RoundId; public override async void Opened() { @@ -58,8 +59,8 @@ public sealed class AdminLogsEui : BaseEui _adminManager.OnPermsChanged += OnPermsChanged; - var roundId = _filter.Round ?? EntitySystem.Get().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()) + return new AdminLogsEuiState(CurrentRoundId, new Dictionary(), 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().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(); } diff --git a/Content.Server/Administration/Logs/IAdminLogManager.cs b/Content.Server/Administration/Logs/IAdminLogManager.cs index ecb8184dc0..90021e9a36 100644 --- a/Content.Server/Administration/Logs/IAdminLogManager.cs +++ b/Content.Server/Administration/Logs/IAdminLogManager.cs @@ -23,4 +23,5 @@ public interface IAdminLogManager : ISharedAdminLogManager IAsyncEnumerable CurrentRoundMessages(LogFilter? filter = null); IAsyncEnumerable CurrentRoundJson(LogFilter? filter = null); Task CurrentRound(); + Task CountLogs(int round); } diff --git a/Content.Server/Database/ServerDbBase.cs b/Content.Server/Database/ServerDbBase.cs index 96fddf9a40..de7beeca49 100644 --- a/Content.Server/Database/ServerDbBase.cs +++ b/Content.Server/Database/ServerDbBase.cs @@ -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 CountAdminLogs(int round) + { + await using var db = await GetDb(); + return await db.DbContext.AdminLog.CountAsync(log => log.RoundId == round); + } + #endregion #region Whitelist diff --git a/Content.Server/Database/ServerDbManager.cs b/Content.Server/Database/ServerDbManager.cs index 0190013a8e..5dde449b58 100644 --- a/Content.Server/Database/ServerDbManager.cs +++ b/Content.Server/Database/ServerDbManager.cs @@ -205,6 +205,7 @@ namespace Content.Server.Database IAsyncEnumerable GetAdminLogMessages(LogFilter? filter = null); IAsyncEnumerable GetAdminLogs(LogFilter? filter = null); IAsyncEnumerable GetAdminLogsJson(LogFilter? filter = null); + Task CountAdminLogs(int round); #endregion @@ -588,6 +589,12 @@ namespace Content.Server.Database return _db.GetAdminLogsJson(filter); } + public Task CountAdminLogs(int round) + { + DbReadOpsMetric.Inc(); + return _db.CountAdminLogs(round); + } + public Task GetWhitelistStatusAsync(NetUserId player) { DbReadOpsMetric.Inc(); diff --git a/Content.Shared/Administration/Logs/AdminLogsEuiState.cs b/Content.Shared/Administration/Logs/AdminLogsEuiState.cs index 6e4d439c32..fa94fd0b45 100644 --- a/Content.Shared/Administration/Logs/AdminLogsEuiState.cs +++ b/Content.Shared/Administration/Logs/AdminLogsEuiState.cs @@ -7,10 +7,11 @@ namespace Content.Shared.Administration.Logs; [Serializable, NetSerializable] public sealed class AdminLogsEuiState : EuiStateBase { - public AdminLogsEuiState(int roundId, Dictionary players) + public AdminLogsEuiState(int roundId, Dictionary 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 Players { get; } + + public int RoundLogs { get; } } public static class AdminLogsEuiMsg diff --git a/Resources/Locale/en-US/administration/ui/admin-logs.ftl b/Resources/Locale/en-US/administration/ui/admin-logs.ftl index 457048ff56..549e9587d7 100644 --- a/Resources/Locale/en-US/administration/ui/admin-logs.ftl +++ b/Resources/Locale/en-US/administration/ui/admin-logs.ftl @@ -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