feat: compiled queries
This commit is contained in:
parent
aa09d0b755
commit
ecd86d890c
2 changed files with 37 additions and 25 deletions
|
@ -0,0 +1,14 @@
|
|||
// Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License.
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Server.DB;
|
||||
using Server.DB.Documents;
|
||||
|
||||
namespace Server.PacketHandlers;
|
||||
|
||||
public partial class CharacterCreationHandler
|
||||
{
|
||||
private static readonly Func<WonderkingContext, Guid, Task<Account>> _getAccount =
|
||||
EF.CompileQuery((WonderkingContext context, Guid accountId) =>
|
||||
context.Accounts.FirstOrDefaultAsync(a => a.Id == accountId, default));
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
// Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License.
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NetCoreServer;
|
||||
using Server.DB;
|
||||
using Server.DB.Documents;
|
||||
|
@ -13,7 +12,7 @@ using Wonderking.Packets.Outgoing.Data;
|
|||
|
||||
namespace Server.PacketHandlers;
|
||||
|
||||
public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
|
||||
public partial class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
|
||||
{
|
||||
private readonly CharacterStatsMappingConfiguration _characterStatsMapping;
|
||||
private readonly ItemObjectPoolService _itemObjectPoolService;
|
||||
|
@ -35,8 +34,8 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
|
|||
return;
|
||||
}
|
||||
|
||||
var account =
|
||||
_wonderkingContext.Accounts.FirstOrDefault(a => a.Id == authSession.AccountId);
|
||||
var account = await
|
||||
_getAccount(_wonderkingContext, authSession.AccountId);
|
||||
|
||||
var firstJobConfig = SelectFirstJobConfig(packet.FirstJob);
|
||||
var items = CreateDefaultItems(packet, firstJobConfig);
|
||||
|
@ -45,27 +44,26 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
|
|||
account?.Characters.Add(toBeAddedCharacter);
|
||||
await _wonderkingContext.SaveChangesAsync();
|
||||
|
||||
var character = await _wonderkingContext.Characters.AsNoTrackingWithIdentityResolution().AsSplitQuery()
|
||||
.Where(c => c.Account.Id == authSession.AccountId && c.Name == packet.Name)
|
||||
.Select(c =>
|
||||
var character =
|
||||
new CharacterData
|
||||
{
|
||||
Name = c.Name,
|
||||
Job = c.JobData,
|
||||
Gender = c.Gender,
|
||||
Level = c.Level,
|
||||
Experience = c.Experience,
|
||||
Stats = c.BaseStats,
|
||||
Health = c.Health,
|
||||
Mana = c.Mana,
|
||||
Name = toBeAddedCharacter.Name,
|
||||
Job = toBeAddedCharacter.JobData,
|
||||
Gender = toBeAddedCharacter.Gender,
|
||||
Level = toBeAddedCharacter.Level,
|
||||
Experience = toBeAddedCharacter.Experience,
|
||||
Stats = toBeAddedCharacter.BaseStats,
|
||||
Health = toBeAddedCharacter.Health,
|
||||
Mana = toBeAddedCharacter.Mana,
|
||||
EquippedItems =
|
||||
GetItemIDsByInventoryTab(c.InventoryItems
|
||||
GetItemIDsByInventoryTab(toBeAddedCharacter.InventoryItems
|
||||
.Where(item => item.InventoryTab == InventoryTab.WornEquipment)
|
||||
.Select(item => new Tuple<ushort, byte>(item.ItemId, item.Slot)).AsEnumerable()),
|
||||
EquippedCashItems = GetItemIDsByInventoryTab(c.InventoryItems
|
||||
EquippedCashItems = GetItemIDsByInventoryTab(toBeAddedCharacter.InventoryItems
|
||||
.Where(item => item.InventoryTab == InventoryTab.WornCashEquipment)
|
||||
.Select(item => new Tuple<ushort, byte>(item.ItemId, item.Slot)).AsEnumerable())
|
||||
}).FirstAsync();
|
||||
};
|
||||
|
||||
await authSession.SendAsync(new CharacterCreationResponsePacket
|
||||
{
|
||||
Character = character,
|
||||
|
|
Loading…
Reference in a new issue