From 7f3d064ec41ddb20cf262c0bd3be095abc32f426 Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Wed, 13 Oct 2021 21:11:20 +0200 Subject: [PATCH] Fix character slot deletion on postgres. Fixes #4860 --- Content.Server/Database/ServerDbBase.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Content.Server/Database/ServerDbBase.cs b/Content.Server/Database/ServerDbBase.cs index 5e9f67707a..143b50aada 100644 --- a/Content.Server/Database/ServerDbBase.cs +++ b/Content.Server/Database/ServerDbBase.cs @@ -56,7 +56,7 @@ namespace Content.Server.Database if (profile is null) { - DeleteCharacterSlot(db.DbContext, userId, slot); + await DeleteCharacterSlot(db.DbContext, userId, slot); await db.DbContext.SaveChangesAsync(); return; } @@ -87,12 +87,13 @@ namespace Content.Server.Database await db.DbContext.SaveChangesAsync(); } - private static void DeleteCharacterSlot(ServerDbContext db, NetUserId userId, int slot) + private static async Task DeleteCharacterSlot(ServerDbContext db, NetUserId userId, int slot) { - db.Preference - .Single(p => p.UserId == userId.UserId) - .Profiles - .RemoveAll(h => h.Slot == slot); + var profile = await db.Profile.Include(p => p.Preference) + .Where(p => p.Preference.UserId == userId.UserId && p.Slot == slot) + .SingleOrDefaultAsync(); + + db.Profile.Remove(profile); } public async Task InitPrefsAsync(NetUserId userId, ICharacterProfile defaultProfile) @@ -120,7 +121,7 @@ namespace Content.Server.Database { await using var db = await GetDb(); - DeleteCharacterSlot(db.DbContext, userId, deleteSlot); + await DeleteCharacterSlot(db.DbContext, userId, deleteSlot); await SetSelectedCharacterSlotAsync(userId, newSlot, db.DbContext); await db.DbContext.SaveChangesAsync();