Pools admin log lists (#11462)
Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -299,7 +299,7 @@ public sealed partial class AdminLogManager : SharedAdminLogManager, IAdminLogMa
|
||||
Add(type, LogImpact.Medium, ref handler);
|
||||
}
|
||||
|
||||
public async Task<List<SharedAdminLog>> All(LogFilter? filter = null)
|
||||
public async Task<List<SharedAdminLog>> All(LogFilter? filter = null, Func<List<SharedAdminLog>>? 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<SharedAdminLog>(initialSize);
|
||||
List<SharedAdminLog> list;
|
||||
if (listProvider != null)
|
||||
{
|
||||
list = listProvider();
|
||||
list.EnsureCapacity(initialSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
list = new List<SharedAdminLog>(initialSize);
|
||||
}
|
||||
|
||||
await foreach (var log in _db.GetAdminLogs(filter).WithCancellation(filter?.CancellationToken ?? default))
|
||||
{
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -15,7 +15,7 @@ public interface IAdminLogManager : ISharedAdminLogManager
|
||||
void RoundStarting(int id);
|
||||
void RunLevelChanged(GameRunLevel level);
|
||||
|
||||
Task<List<SharedAdminLog>> All(LogFilter? filter = null);
|
||||
Task<List<SharedAdminLog>> All(LogFilter? filter = null, Func<List<SharedAdminLog>>? listProvider = null);
|
||||
IAsyncEnumerable<string> AllMessages(LogFilter? filter = null);
|
||||
IAsyncEnumerable<JsonDocument> AllJson(LogFilter? filter = null);
|
||||
Task<Round> Round(int roundId);
|
||||
|
||||
Reference in New Issue
Block a user