Cache the last 3 rounds of admin logs in memory
Reduces send logs time from 2/10/45 seconds to 2 milliseconds Not thread safe Removes LogRecord
This commit is contained in:
@@ -147,21 +147,17 @@ public sealed class AdminLogsEui : BaseEui
|
||||
stopwatch.Start();
|
||||
|
||||
// TODO ADMIN LOGS array pool
|
||||
var logs = new List<SharedAdminLog>(_clientBatchSize);
|
||||
List<SharedAdminLog> logs = default!;
|
||||
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
var results = await Task.Run(() => _logSystem.All(_filter));
|
||||
|
||||
await foreach (var record in results.WithCancellation(_logSendCancellation.Token))
|
||||
{
|
||||
var log = new SharedAdminLog(record.Id, record.Type, record.Impact, record.Date, record.Message, record.Players);
|
||||
logs.Add(log);
|
||||
}
|
||||
logs = await _logSystem.All(_filter);
|
||||
}, _filter.CancellationToken);
|
||||
|
||||
if (logs.Count > 0)
|
||||
{
|
||||
_filter.LogsSent += logs.Count;
|
||||
|
||||
var largestId = _filter.DateOrder switch
|
||||
{
|
||||
DateOrder.Ascending => ^1,
|
||||
@@ -172,7 +168,7 @@ public sealed class AdminLogsEui : BaseEui
|
||||
_filter.LastLogId = logs[largestId].Id;
|
||||
}
|
||||
|
||||
var message = new NewLogs(logs.ToArray(), replace);
|
||||
var message = new NewLogs(logs, replace);
|
||||
|
||||
SendMessage(message);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user