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
This commit is contained in:
DrSmugleaf
2023-05-17 04:04:28 -07:00
committed by GitHub
parent 9ef5bd389c
commit b5fe408baf
10 changed files with 59 additions and 20 deletions

View 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)

View 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)
{

View 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>

View 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);
}
}

View 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();
}

View 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);
}

View 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

View 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();

View 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

View 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