fix(ssr): only use 1 network request to fetch map ids
All checks were successful
deploy / deploy (push) Successful in 58s
All checks were successful
deploy / deploy (push) Successful in 58s
This commit is contained in:
parent
3dd2fc48ad
commit
af707a8c79
@ -19,14 +19,15 @@ export async function GET(request: Request) {
|
|||||||
const map = await BeatsaverAPI.fetchMapByHash(mapHash);
|
const map = await BeatsaverAPI.fetchMapByHash(mapHash);
|
||||||
if (map) {
|
if (map) {
|
||||||
maps[mapHash] = map;
|
maps[mapHash] = map;
|
||||||
|
mapCache.set(mapHash, map);
|
||||||
}
|
}
|
||||||
if (map && idOnly) {
|
if (map && idOnly) {
|
||||||
maps[mapHash] = { id: map.id };
|
maps[mapHash] = { id: map.id };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Response(JSON.stringify(maps), {
|
|
||||||
headers: { "content-type": "application/json;charset=UTF-8" },
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new Response(JSON.stringify(maps), {
|
||||||
|
headers: { "content-type": "application/json;charset=UTF-8" },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -162,24 +162,28 @@ async function fetchScoresWithBeatsaverData(
|
|||||||
string,
|
string,
|
||||||
ScoresaberScoreWithBeatsaverData
|
ScoresaberScoreWithBeatsaverData
|
||||||
> = {};
|
> = {};
|
||||||
|
|
||||||
|
let url = `${
|
||||||
|
isProduction() ? ssrSettings.siteUrl : "http://localhost:3000"
|
||||||
|
}/api/beatsaver/mapdata?hashes=`;
|
||||||
for (const score of scores) {
|
for (const score of scores) {
|
||||||
const mapResponse = await fetch(
|
url += `${score.leaderboard.songHash},`;
|
||||||
`${
|
}
|
||||||
isProduction() ? ssrSettings.siteUrl : "http://localhost:3000"
|
const mapResponse = await fetch(url, {
|
||||||
}/api/beatsaver/mapdata?hashes=${score.leaderboard.songHash}&idonly=true`,
|
next: {
|
||||||
{
|
revalidate: 60 * 60 * 24 * 7, // 1 week
|
||||||
next: {
|
},
|
||||||
revalidate: 60 * 60 * 24 * 7, // 1 week
|
});
|
||||||
},
|
const mapJson = await mapResponse.json();
|
||||||
},
|
for (const score of scores) {
|
||||||
);
|
const mapData = mapJson[score.leaderboard.songHash];
|
||||||
const mapData = await mapResponse.json();
|
if (mapData) {
|
||||||
const mapId = mapData[score.leaderboard.songHash].id;
|
scoresWithBeatsaverData[score.leaderboard.songHash] = {
|
||||||
scoresWithBeatsaverData[score.score.id] = {
|
score: score.score,
|
||||||
score: score.score,
|
leaderboard: score.leaderboard,
|
||||||
leaderboard: score.leaderboard,
|
mapId: mapData.id,
|
||||||
mapId: mapId,
|
};
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user