perf(channelserver): move UserBinary and minidata to memory-only

UserBinary type1-5 and EnhancedMinidata are transient session state
resent by the client on every login. Persisting them to the DB on
every set was unnecessary I/O. Both are now served exclusively from
server-scoped in-memory maps (userBinaryParts, minidataParts).

Includes a schema migration to drop the now-unused type2/type3
columns from user_binary and minidata column from characters.

Ref #158
This commit is contained in:
Houmgaor
2026-02-19 00:05:20 +01:00
parent b2b1c426a5
commit 99e544e0cf
6 changed files with 38 additions and 46 deletions

View File

@@ -211,11 +211,12 @@ func handleMsgMhfUseUdShopCoin(s *Session, p mhfpacket.MHFPacket) {}
func handleMsgMhfGetEnhancedMinidata(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfGetEnhancedMinidata)
// this looks to be the detailed chunk of information you can pull up on players in town
var data []byte
err := s.server.db.QueryRow("SELECT minidata FROM characters WHERE id = $1", pkt.CharID).Scan(&data)
if err != nil {
s.logger.Error("Failed to load minidata")
s.server.minidataLock.RLock()
data, ok := s.server.minidataParts[pkt.CharID]
s.server.minidataLock.RUnlock()
if !ok {
data = make([]byte, 1)
}
doAckBufSucceed(s, pkt.AckHandle, data)
@@ -224,10 +225,11 @@ func handleMsgMhfGetEnhancedMinidata(s *Session, p mhfpacket.MHFPacket) {
func handleMsgMhfSetEnhancedMinidata(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfSetEnhancedMinidata)
dumpSaveData(s, pkt.RawDataPayload, "minidata")
_, err := s.server.db.Exec("UPDATE characters SET minidata=$1 WHERE id=$2", pkt.RawDataPayload, s.charID)
if err != nil {
s.logger.Error("Failed to save minidata", zap.Error(err))
}
s.server.minidataLock.Lock()
s.server.minidataParts[s.charID] = pkt.RawDataPayload
s.server.minidataLock.Unlock()
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
}