mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-27 01:53:19 +01:00
refactor(channelserver): eliminate *sqlx.Rows/*sql.Rows from repository interfaces
Move scan loops from handlers into repository methods so that interfaces return typed slices instead of leaking database cursors. This fixes resource leaks (7 of 12 call sites never closed rows) and makes all 12 methods mockable for unit tests. Affected repos: CafeRepo, ShopRepo, EventRepo, RengokuRepo, DivaRepo, ScenarioRepo, MiscRepo, MercenaryRepo. New structs: DivaEvent, MercenaryLoan, GuildHuntCatUsage. EventRepo.GetEventQuests left as-is (requires broader Server refactor).
This commit is contained in:
@@ -20,22 +20,12 @@ type Scenario struct {
|
||||
|
||||
func handleMsgMhfInfoScenarioCounter(s *Session, p mhfpacket.MHFPacket) {
|
||||
pkt := p.(*mhfpacket.MsgMhfInfoScenarioCounter)
|
||||
var scenarios []Scenario
|
||||
var scenario Scenario
|
||||
scenarioData, err := s.server.scenarioRepo.GetCounters()
|
||||
scenarios, err := s.server.scenarioRepo.GetCounters()
|
||||
if err != nil {
|
||||
_ = scenarioData.Close()
|
||||
s.logger.Error("Failed to get scenario counter info from db", zap.Error(err))
|
||||
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 1))
|
||||
return
|
||||
}
|
||||
for scenarioData.Next() {
|
||||
err = scenarioData.Scan(&scenario.MainID, &scenario.CategoryID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
scenarios = append(scenarios, scenario)
|
||||
}
|
||||
|
||||
// Trim excess scenarios
|
||||
if len(scenarios) > 128 {
|
||||
|
||||
Reference in New Issue
Block a user