Optimizations. User-Role handling in templates and routes.

This commit is contained in:
MaxJa4
2024-01-21 17:24:29 +01:00
parent 8edbbb4347
commit 4aae0896aa
14 changed files with 221 additions and 119 deletions

View File

@@ -41,6 +41,34 @@ func GetScore(playerId uint, gameTag string) (float32, error) {
}
}
func GetScores(players []models.Player, gameTag string) ([]float32, error) {
vals, err := models.Cache.Pipelined(ctx, func(pipe redis.Pipeliner) error {
for _, p := range players {
key := GetPlayerCacheKey(p.ID, gameTag)
pipe.Get(ctx, key)
}
return nil
})
if err != nil && !errors.Is(err, redis.Nil) {
return nil, err
}
var scores []float32
for _, val := range vals {
score, err := val.(*redis.StringCmd).Float32()
if errors.Is(err, redis.Nil) { // cache miss
score = -1
err = nil
} else if err != nil { // cache error
score = -1
}
scores = append(scores, score)
}
return scores, nil
}
func DeleteScore(playerId uint, gameTag string) error {
key := GetPlayerCacheKey(playerId, gameTag)
return models.Cache.Del(ctx, key).Err()