Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions internal/core/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading