From d78a97e09769c8453065787e023c7a3b4d7b6afd Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 5 Jun 2026 12:01:50 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Use=20HGet=20instead=20of?= =?UTF-8?q?=20HGetAll=20for=20session=20status=20checks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: arumes31 <114224498+arumes31@users.noreply.github.com> --- internal/core/redis.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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)