Pools admin log lists (#11462)

Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
Paul Ritter
2022-10-17 00:00:30 +02:00
committed by GitHub
parent 64926102ff
commit 8b1580ee30
3 changed files with 21 additions and 10 deletions

View File

@@ -8,8 +8,10 @@ using Content.Shared.Administration;
using Content.Shared.Administration.Logs;
using Content.Shared.CCVar;
using Content.Shared.Eui;
using Microsoft.Extensions.ObjectPool;
using Robust.Shared.Configuration;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using static Content.Shared.Administration.Logs.AdminLogsEuiMsg;
namespace Content.Server.Administration.Logs;
@@ -29,6 +31,9 @@ public sealed class AdminLogsEui : BaseEui
private CancellationTokenSource _logSendCancellation = new();
private LogFilter _filter;
private DefaultObjectPool<List<SharedAdminLog>> _adminLogListPool =
new(new ListPolicy<SharedAdminLog>());
public AdminLogsEui()
{
IoCManager.InjectDependencies(this);
@@ -140,13 +145,8 @@ public sealed class AdminLogsEui : BaseEui
var stopwatch = new Stopwatch();
stopwatch.Start();
// TODO ADMIN LOGS array pool
List<SharedAdminLog> logs = default!;
await Task.Run(async () =>
{
logs = await _adminLogs.All(_filter);
}, _filter.CancellationToken);
var logs = await Task.Run(async () => await _adminLogs.All(_filter, _adminLogListPool.Get),
_filter.CancellationToken);
if (logs.Count > 0)
{
@@ -167,6 +167,8 @@ public sealed class AdminLogsEui : BaseEui
SendMessage(message);
_sawmill.Info($"Sent {logs.Count} logs to {Player.Name} in {stopwatch.Elapsed.TotalMilliseconds} ms");
_adminLogListPool.Return(logs);
}
public override void Closed()