From 14602dc11a64b57f57c5f6b85b16e8e3bdd407c5 Mon Sep 17 00:00:00 2001 From: Liam <67254223+RealFascinated@users.noreply.github.com> Date: Thu, 20 Oct 2022 18:36:26 +0100 Subject: [PATCH] BL star endpoint actually gets cached??? --- pages/api/beatleader/stars.js | 12 ++++-------- src/components/ScoreStats.js | 6 +++++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pages/api/beatleader/stars.js b/pages/api/beatleader/stars.js index 34b9d12..5ae4b5c 100644 --- a/pages/api/beatleader/stars.js +++ b/pages/api/beatleader/stars.js @@ -15,11 +15,10 @@ export default async function handler(req, res) { const difficulty = req.query.difficulty.replace(" ", ""); const characteristic = req.query.characteristic; - const exists = await RedisUtils.exists(`${KEY}${mapHash}`); + const key = `${KEY}${difficulty}-${characteristic}-${mapHash}`; + const exists = await RedisUtils.exists(key); if (exists) { - const data = await RedisUtils.getValue( - `${KEY}${difficulty}-${characteristic}-${mapHash}`.replace(" ", "") - ); + const data = await RedisUtils.getValue(key); res.setHeader("Cache-Status", "hit"); return res.status(200).json({ @@ -46,10 +45,7 @@ export default async function handler(req, res) { }); } const json = await data.json(); - RedisUtils.setValue( - `${KEY}${difficulty}-${characteristic}-${mapHash}`.replace(" ", ""), - json.difficulty.stars - ); + RedisUtils.setValue(key, json.difficulty.stars); res.setHeader("Cache-Status", "miss"); return res.status(200).json({ status: "OK", diff --git a/src/components/ScoreStats.js b/src/components/ScoreStats.js index e025688..77628a6 100644 --- a/src/components/ScoreStats.js +++ b/src/components/ScoreStats.js @@ -26,9 +26,13 @@ export default class ScoreStats extends Component { data.percentage.replace("%", ""), data.websiteType ); - if (this.lastKnownPP === undefined || this.lastKnownPP < currentPP) { + if (this.lastKnownPP === undefined) { + this.lastKnownPP = currentPP; + } + if (currentPP < this.lastKnownPP || currentPP === undefined) { currentPP = this.lastKnownPP; } + this.lastKnownPP = currentPP; return (