disable cache for now

This commit is contained in:
Lee 2024-10-09 18:01:51 +01:00
parent 2ebc04243c
commit 392f7c0db8
3 changed files with 2 additions and 22 deletions

@ -5,7 +5,6 @@ import { getAverageColor } from "@/common/image-utils";
import { LeaderboardData } from "@/components/leaderboard/leaderboard-data"; import { LeaderboardData } from "@/components/leaderboard/leaderboard-data";
import { scoresaberService } from "@ssr/common/service/impl/scoresaber"; import { scoresaberService } from "@ssr/common/service/impl/scoresaber";
import ScoreSaberLeaderboardScoresPageToken from "@ssr/common/types/token/scoresaber/score-saber-leaderboard-scores-page-token"; 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"; import ScoreSaberLeaderboardToken from "@ssr/common/types/token/scoresaber/score-saber-leaderboard-token";
const UNKNOWN_LEADERBOARD = { const UNKNOWN_LEADERBOARD = {
@ -28,8 +27,6 @@ type LeaderboardData = {
page: number; page: number;
}; };
const leaderboardCache = new NodeCache({ stdTTL: 60, checkperiod: 120 });
/** /**
* Gets the leaderboard data and scores * Gets the leaderboard data and scores
* *
@ -42,24 +39,17 @@ const getLeaderboardData = async ({ params }: Props, fetchScores: boolean = true
const id = slug[0]; // The leaderboard id const id = slug[0]; // The leaderboard id
const page = parseInt(slug[1]) || 1; // The page number 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); const leaderboard = await scoresaberService.lookupLeaderboard(id);
let scores: ScoreSaberLeaderboardScoresPageToken | undefined; let scores: ScoreSaberLeaderboardScoresPageToken | undefined;
if (fetchScores) { if (fetchScores) {
scores = await scoresaberService.lookupLeaderboardScores(id + "", page); scores = await scoresaberService.lookupLeaderboardScores(id + "", page);
} }
const leaderboardData = { return {
page: page, page: page,
leaderboard: leaderboard, leaderboard: leaderboard,
scores: scores, scores: scores,
}; };
leaderboardCache.set(cacheId, leaderboardData);
return leaderboardData;
}; };
export async function generateMetadata(props: Props): Promise<Metadata> { export async function generateMetadata(props: Props): Promise<Metadata> {

@ -35,8 +35,6 @@ type PlayerData = {
search: string; search: string;
}; };
const playerCache = new NodeCache({ stdTTL: 60, checkperiod: 120 });
/** /**
* Gets the player data and scores * Gets the player data and scores
* *
@ -51,11 +49,6 @@ const getPlayerData = async ({ params }: Props, fetchScores: boolean = true): Pr
const page = parseInt(slug[2]) || 1; // The page number const page = parseInt(slug[2]) || 1; // The page number
const search = (slug[3] as string) || ""; // The search query 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 playerToken = await scoresaberService.lookupPlayer(id);
const player = const player =
playerToken && (await getScoreSaberPlayerFromToken(playerToken, config.siteApi, cookies().get("playerId")?.value)); playerToken && (await getScoreSaberPlayerFromToken(playerToken, config.siteApi, cookies().get("playerId")?.value));
@ -69,15 +62,13 @@ const getPlayerData = async ({ params }: Props, fetchScores: boolean = true): Pr
}); });
} }
const playerData = { return {
sort: sort, sort: sort,
page: page, page: page,
search: search, search: search,
player: player, player: player,
scores: scores, scores: scores,
}; };
playerCache.set(cacheId, playerData);
return playerData;
}; };
export async function generateMetadata(props: Props): Promise<Metadata> { export async function generateMetadata(props: Props): Promise<Metadata> {

@ -1,5 +1,4 @@
import { config } from "../../config"; import { config } from "../../config";
import { cache } from "react";
/** /**
* Proxies all non-localhost images to make them load faster. * Proxies all non-localhost images to make them load faster.