Fix admin logs duplicate id error when running tests (#16203)
This commit is contained in:
@@ -12,7 +12,6 @@ using Content.Shared.Preferences;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Database
|
||||
{
|
||||
@@ -717,26 +716,10 @@ INSERT INTO player_round (players_id, rounds_id) VALUES ({players[player]}, {id}
|
||||
return (server, false);
|
||||
}
|
||||
|
||||
public virtual async Task AddAdminLogs(List<QueuedLog> logs)
|
||||
public async Task AddAdminLogs(List<AdminLog> logs)
|
||||
{
|
||||
await using var db = await GetDb();
|
||||
|
||||
var entities = new Dictionary<int, AdminLogEntity>();
|
||||
|
||||
foreach (var (log, entityData) in logs)
|
||||
{
|
||||
var logEntities = new List<AdminLogEntity>(entityData.Count);
|
||||
foreach (var (id, name) in entityData)
|
||||
{
|
||||
var entity = entities.GetOrNew(id);
|
||||
entity.Name = name;
|
||||
logEntities.Add(entity);
|
||||
}
|
||||
|
||||
log.Entities = logEntities;
|
||||
db.DbContext.AdminLog.Add(log);
|
||||
}
|
||||
|
||||
db.DbContext.AdminLog.AddRange(logs);
|
||||
await db.DbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ namespace Content.Server.Database
|
||||
#region Admin Logs
|
||||
|
||||
Task<Server> AddOrGetServer(string serverName);
|
||||
Task AddAdminLogs(List<QueuedLog> logs);
|
||||
Task AddAdminLogs(List<AdminLog> logs);
|
||||
IAsyncEnumerable<string> GetAdminLogMessages(LogFilter? filter = null);
|
||||
IAsyncEnumerable<SharedAdminLog> GetAdminLogs(LogFilter? filter = null);
|
||||
IAsyncEnumerable<JsonDocument> GetAdminLogsJson(LogFilter? filter = null);
|
||||
@@ -564,7 +564,7 @@ namespace Content.Server.Database
|
||||
return server;
|
||||
}
|
||||
|
||||
public Task AddAdminLogs(List<QueuedLog> logs)
|
||||
public Task AddAdminLogs(List<AdminLog> logs)
|
||||
{
|
||||
DbWriteOpsMetric.Inc();
|
||||
return RunDbCommand(() => _db.AddAdminLogs(logs));
|
||||
|
||||
@@ -3,14 +3,12 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.IP;
|
||||
using Content.Server.Preferences.Managers;
|
||||
using Content.Shared.CCVar;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Database
|
||||
{
|
||||
@@ -475,42 +473,6 @@ namespace Content.Server.Database
|
||||
return round.Id;
|
||||
}
|
||||
|
||||
public override async Task AddAdminLogs(List<QueuedLog> logs)
|
||||
{
|
||||
await using var db = await GetDb();
|
||||
|
||||
var nextId = 1;
|
||||
if (await db.DbContext.AdminLog.AnyAsync())
|
||||
{
|
||||
nextId = db.DbContext.AdminLog.Max(round => round.Id) + 1;
|
||||
}
|
||||
|
||||
var entities = new Dictionary<int, AdminLogEntity>();
|
||||
|
||||
foreach (var (log, entityData) in logs)
|
||||
{
|
||||
log.Id = nextId++;
|
||||
|
||||
var logEntities = new List<AdminLogEntity>(entityData.Count);
|
||||
foreach (var (id, name) in entityData)
|
||||
{
|
||||
var entity = entities.GetOrNew(id);
|
||||
entity.Name = name;
|
||||
logEntities.Add(entity);
|
||||
}
|
||||
|
||||
foreach (var player in log.Players)
|
||||
{
|
||||
player.LogId = log.Id;
|
||||
}
|
||||
|
||||
log.Entities = logEntities;
|
||||
db.DbContext.AdminLog.Add(log);
|
||||
}
|
||||
|
||||
await db.DbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public override async Task<int> AddAdminNote(AdminNote note)
|
||||
{
|
||||
await using (var db = await GetDb())
|
||||
|
||||
Reference in New Issue
Block a user