add cache to the player data fetching on the player page to speedup initial page loads
Some checks failed
Deploy / deploy (push) Has been cancelled
Some checks failed
Deploy / deploy (push) Has been cancelled
This commit is contained in:
parent
b5071fd420
commit
5f1ee985fb
@ -8,6 +8,7 @@ import { redirect } from "next/navigation";
|
|||||||
import { Colors } from "@/common/colors";
|
import { Colors } from "@/common/colors";
|
||||||
import ScoreSaberPlayerScoresPageToken from "@/common/model/token/scoresaber/score-saber-player-scores-page-token";
|
import ScoreSaberPlayerScoresPageToken from "@/common/model/token/scoresaber/score-saber-player-scores-page-token";
|
||||||
import { getAverageColor } from "@/common/image-utils";
|
import { getAverageColor } from "@/common/image-utils";
|
||||||
|
import { cache } from "react";
|
||||||
|
|
||||||
const UNKNOWN_PLAYER = {
|
const UNKNOWN_PLAYER = {
|
||||||
title: "ScoreSaber Reloaded - Unknown Player",
|
title: "ScoreSaber Reloaded - Unknown Player",
|
||||||
@ -30,7 +31,8 @@ type Props = {
|
|||||||
* @param fetchScores whether to fetch the scores
|
* @param fetchScores whether to fetch the scores
|
||||||
* @returns the player data and scores
|
* @returns the player data and scores
|
||||||
*/
|
*/
|
||||||
async function getPlayerData({ params }: Props, fetchScores: boolean = true) {
|
const getPlayerData = cache(
|
||||||
|
async ({ params }: Props, fetchScores: boolean = true) => {
|
||||||
const { slug } = await params;
|
const { slug } = await params;
|
||||||
const id = slug[0]; // The players id
|
const id = slug[0]; // The players id
|
||||||
const sort: ScoreSort = (slug[1] as ScoreSort) || "recent"; // The sorting method
|
const sort: ScoreSort = (slug[1] as ScoreSort) || "recent"; // The sorting method
|
||||||
@ -55,7 +57,8 @@ async function getPlayerData({ params }: Props, fetchScores: boolean = true) {
|
|||||||
player: player,
|
player: player,
|
||||||
scores: scores,
|
scores: scores,
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
|
);
|
||||||
|
|
||||||
export async function generateMetadata(props: Props): Promise<Metadata> {
|
export async function generateMetadata(props: Props): Promise<Metadata> {
|
||||||
const { player } = await getPlayerData(props, false);
|
const { player } = await getPlayerData(props, false);
|
||||||
|
Reference in New Issue
Block a user