diff --git a/Content.Server/Administration/Logs/AdminLogManager.cs b/Content.Server/Administration/Logs/AdminLogManager.cs index 0b0625bba2..4b40f77232 100644 --- a/Content.Server/Administration/Logs/AdminLogManager.cs +++ b/Content.Server/Administration/Logs/AdminLogManager.cs @@ -299,7 +299,7 @@ public sealed partial class AdminLogManager : SharedAdminLogManager, IAdminLogMa Add(type, LogImpact.Medium, ref handler); } - public async Task> All(LogFilter? filter = null) + public async Task> All(LogFilter? filter = null, Func>? listProvider = null) { if (TrySearchCache(filter, out var results)) { @@ -307,7 +307,16 @@ public sealed partial class AdminLogManager : SharedAdminLogManager, IAdminLogMa } var initialSize = Math.Min(filter?.Limit ?? 0, 1000); - var list = new List(initialSize); + List list; + if (listProvider != null) + { + list = listProvider(); + list.EnsureCapacity(initialSize); + } + else + { + list = new List(initialSize); + } await foreach (var log in _db.GetAdminLogs(filter).WithCancellation(filter?.CancellationToken ?? default)) { diff --git a/Content.Server/Administration/Logs/AdminLogsEui.cs b/Content.Server/Administration/Logs/AdminLogsEui.cs index 1851778131..8b0366faf1 100644 --- a/Content.Server/Administration/Logs/AdminLogsEui.cs +++ b/Content.Server/Administration/Logs/AdminLogsEui.cs @@ -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> _adminLogListPool = + new(new ListPolicy()); + 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 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() diff --git a/Content.Server/Administration/Logs/IAdminLogManager.cs b/Content.Server/Administration/Logs/IAdminLogManager.cs index 47a4da6f57..ecb8184dc0 100644 --- a/Content.Server/Administration/Logs/IAdminLogManager.cs +++ b/Content.Server/Administration/Logs/IAdminLogManager.cs @@ -15,7 +15,7 @@ public interface IAdminLogManager : ISharedAdminLogManager void RoundStarting(int id); void RunLevelChanged(GameRunLevel level); - Task> All(LogFilter? filter = null); + Task> All(LogFilter? filter = null, Func>? listProvider = null); IAsyncEnumerable AllMessages(LogFilter? filter = null); IAsyncEnumerable AllJson(LogFilter? filter = null); Task Round(int roundId);