cap limit, cache key contains limit

This commit is contained in:
2021-10-23 23:32:36 +02:00
parent e394521755
commit 3124a849f1
2 changed files with 9 additions and 3 deletions

10
main.go
View File

@@ -164,6 +164,12 @@ func getPlayerMeta(w http.ResponseWriter, r *http.Request) {
limit = 4
}
if limit > 10 {
log.Infof("[GPM] limit out of bounds: %d", limit)
w.WriteHeader(http.StatusBadRequest)
return
}
tPlayer, err := utils.GetPlayer(db, id, conf.Steam.APIKey, nil)
if err != nil {
log.Infof("[GP] Player not found: %+v", err)
@@ -172,7 +178,7 @@ func getPlayerMeta(w http.ResponseWriter, r *http.Request) {
}
metaStats := new(utils.MetaStatsResponse)
err = rdc.Get(context.Background(), fmt.Sprintf(utils.SideMetaCacheKey, tPlayer.ID), &metaStats)
err = rdc.Get(context.Background(), fmt.Sprintf(utils.SideMetaCacheKey, tPlayer.ID, limit), &metaStats)
if err != nil {
metaStats, err = utils.GetMetaStats(tPlayer, db.Lock, limit)
if err != nil {
@@ -183,7 +189,7 @@ func getPlayerMeta(w http.ResponseWriter, r *http.Request) {
err = rdc.Set(&cache.Item{
Ctx: context.Background(),
Key: fmt.Sprintf(utils.SideMetaCacheKey, tPlayer.ID),
Key: fmt.Sprintf(utils.SideMetaCacheKey, tPlayer.ID, limit),
Value: metaStats,
TTL: time.Hour * 24 * 30,
})