This commit is contained in:
parent
0293e50cee
commit
a69cf8a033
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
@ -37,9 +37,9 @@
|
||||
"next-build-id": "^3.0.0",
|
||||
"next-themes": "^0.3.0",
|
||||
"node-cache": "^5.1.2",
|
||||
"react": "19.0.0-rc-d5bba18b-20241009",
|
||||
"react": "19.0.0-rc-3edc000d-20240926",
|
||||
"react-chartjs-2": "^5.2.0",
|
||||
"react-dom": "19.0.0-rc-d5bba18b-20241009",
|
||||
"react-dom": "19.0.0-rc-3edc000d-20240926",
|
||||
"react-hook-form": "^7.53.0",
|
||||
"tailwind-merge": "^2.5.2",
|
||||
"tailwindcss-animate": "^1.0.7",
|
||||
|
@ -5,6 +5,7 @@ import { getAverageColor } from "@/common/image-utils";
|
||||
import { LeaderboardData } from "@/components/leaderboard/leaderboard-data";
|
||||
import { scoresaberService } from "@ssr/common/service/impl/scoresaber";
|
||||
import ScoreSaberLeaderboardScoresPageToken from "@ssr/common/types/token/scoresaber/score-saber-leaderboard-scores-page-token";
|
||||
import NodeCache from "node-cache";
|
||||
import ScoreSaberLeaderboardToken from "@ssr/common/types/token/scoresaber/score-saber-leaderboard-token";
|
||||
|
||||
const UNKNOWN_LEADERBOARD = {
|
||||
@ -27,6 +28,8 @@ type LeaderboardData = {
|
||||
page: number;
|
||||
};
|
||||
|
||||
const leaderboardCache = new NodeCache({ stdTTL: 60, checkperiod: 120 });
|
||||
|
||||
/**
|
||||
* Gets the leaderboard data and scores
|
||||
*
|
||||
@ -39,17 +42,25 @@ const getLeaderboardData = async ({ params }: Props, fetchScores: boolean = true
|
||||
const id = slug[0]; // The leaderboard id
|
||||
const page = parseInt(slug[1]) || 1; // The page number
|
||||
|
||||
const cacheId = `${id}-${page}`;
|
||||
if (leaderboardCache.has(cacheId)) {
|
||||
return leaderboardCache.get(cacheId) as LeaderboardData;
|
||||
}
|
||||
|
||||
const leaderboard = await scoresaberService.lookupLeaderboard(id);
|
||||
let scores: ScoreSaberLeaderboardScoresPageToken | undefined;
|
||||
if (fetchScores) {
|
||||
scores = await scoresaberService.lookupLeaderboardScores(id + "", page);
|
||||
}
|
||||
|
||||
return {
|
||||
const leaderboardData = {
|
||||
page: page,
|
||||
leaderboard: leaderboard,
|
||||
scores: scores,
|
||||
};
|
||||
|
||||
leaderboardCache.set(cacheId, leaderboardData);
|
||||
return leaderboardData;
|
||||
};
|
||||
|
||||
export async function generateMetadata(props: Props): Promise<Metadata> {
|
||||
|
@ -35,6 +35,8 @@ type PlayerData = {
|
||||
search: string;
|
||||
};
|
||||
|
||||
const playerCache = new NodeCache({ stdTTL: 60, checkperiod: 120 });
|
||||
|
||||
/**
|
||||
* Gets the player data and scores
|
||||
*
|
||||
@ -49,6 +51,11 @@ const getPlayerData = async ({ params }: Props, fetchScores: boolean = true): Pr
|
||||
const page = parseInt(slug[2]) || 1; // The page number
|
||||
const search = (slug[3] as string) || ""; // The search query
|
||||
|
||||
const cacheId = `${id}-${sort}-${page}-${search}`;
|
||||
if (playerCache.has(cacheId)) {
|
||||
return playerCache.get(cacheId) as PlayerData;
|
||||
}
|
||||
|
||||
const playerToken = await scoresaberService.lookupPlayer(id);
|
||||
const player =
|
||||
playerToken && (await getScoreSaberPlayerFromToken(playerToken, config.siteApi, cookies().get("playerId")?.value));
|
||||
@ -62,13 +69,15 @@ const getPlayerData = async ({ params }: Props, fetchScores: boolean = true): Pr
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
const playerData = {
|
||||
sort: sort,
|
||||
page: page,
|
||||
search: search,
|
||||
player: player,
|
||||
scores: scores,
|
||||
};
|
||||
playerCache.set(cacheId, playerData);
|
||||
return playerData;
|
||||
};
|
||||
|
||||
export async function generateMetadata(props: Props): Promise<Metadata> {
|
||||
|
Reference in New Issue
Block a user