Fix character slot deletion on postgres.

Fixes #4860
This commit is contained in:
Pieter-Jan Briers
2021-10-13 21:11:20 +02:00
parent d0472998a6
commit 7f3d064ec4

View File

@@ -56,7 +56,7 @@ namespace Content.Server.Database
if (profile is null) if (profile is null)
{ {
DeleteCharacterSlot(db.DbContext, userId, slot); await DeleteCharacterSlot(db.DbContext, userId, slot);
await db.DbContext.SaveChangesAsync(); await db.DbContext.SaveChangesAsync();
return; return;
} }
@@ -87,12 +87,13 @@ namespace Content.Server.Database
await db.DbContext.SaveChangesAsync(); 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 var profile = await db.Profile.Include(p => p.Preference)
.Single(p => p.UserId == userId.UserId) .Where(p => p.Preference.UserId == userId.UserId && p.Slot == slot)
.Profiles .SingleOrDefaultAsync();
.RemoveAll(h => h.Slot == slot);
db.Profile.Remove(profile);
} }
public async Task<PlayerPreferences> InitPrefsAsync(NetUserId userId, ICharacterProfile defaultProfile) public async Task<PlayerPreferences> InitPrefsAsync(NetUserId userId, ICharacterProfile defaultProfile)
@@ -120,7 +121,7 @@ namespace Content.Server.Database
{ {
await using var db = await GetDb(); await using var db = await GetDb();
DeleteCharacterSlot(db.DbContext, userId, deleteSlot); await DeleteCharacterSlot(db.DbContext, userId, deleteSlot);
await SetSelectedCharacterSlotAsync(userId, newSlot, db.DbContext); await SetSelectedCharacterSlotAsync(userId, newSlot, db.DbContext);
await db.DbContext.SaveChangesAsync(); await db.DbContext.SaveChangesAsync();