diff --git a/internal/core/redis.go b/internal/core/redis.go index fcc953c..450911a 100644 --- a/internal/core/redis.go +++ b/internal/core/redis.go @@ -117,19 +117,19 @@ func HasActiveSessions(ip string) bool { return false } - // ⚡ Bolt optimization: Batch HGetAll requests to avoid N+1 queries. + // ⚡ Bolt optimization: Batch HGet requests to avoid parsing entire hash when only 'status' is needed. pipe := TokenDB.Pipeline() - cmds := make(map[string]*redis.MapStringStringCmd, len(tokens)) + cmds := make(map[string]*redis.StringCmd, len(tokens)) for _, token := range tokens { - cmds[token] = pipe.HGetAll(Ctx, "X-rauth-authtoken="+token) + cmds[token] = pipe.HGet(Ctx, "X-rauth-authtoken="+token, "status") } _, _ = pipe.Exec(Ctx) var stale []interface{} hasActive := false for _, token := range tokens { - data, err := cmds[token].Result() - if err == nil && len(data) > 0 && data["status"] == "valid" { + status, err := cmds[token].Result() + if err == nil && status == "valid" { hasActive = true } else { stale = append(stale, token) @@ -197,18 +197,18 @@ func reconcileIndexSets(pattern string) int64 { continue } - // ⚡ Bolt optimization: Batch HGetAll requests in a pipeline and remove stale tokens variadically. + // ⚡ Bolt optimization: Batch HGet requests to avoid parsing entire hash when only 'status' is needed. pipe := TokenDB.Pipeline() - cmds := make(map[string]*redis.MapStringStringCmd, len(tokens)) + cmds := make(map[string]*redis.StringCmd, len(tokens)) for _, token := range tokens { - cmds[token] = pipe.HGetAll(Ctx, "X-rauth-authtoken="+token) + cmds[token] = pipe.HGet(Ctx, "X-rauth-authtoken="+token, "status") } _, _ = pipe.Exec(Ctx) var stale []interface{} for _, token := range tokens { - data, err := cmds[token].Result() - if err == nil && len(data) > 0 && data["status"] == "valid" { + status, err := cmds[token].Result() + if err == nil && status == "valid" { live++ } else { stale = append(stale, token)