mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 20:19:49 +02:00
fix: use non-caching apis for ratings command
This commit is contained in:
1 parent
4b5e0d1c1c
commit
14710b5218
4 files changed
+35
-38
No files matched your search
@@ -137,15 +137,12 @@ export default function Page() {
|
|||||||
await Promise.all(
|
await Promise.all(
|
||||||
range(0, 5).map(async (league: number) => {
|
range(0, 5).map(async (league: number) => {
|
||||||
const data = await getRatingsLeague(region, league);
|
const data = await getRatingsLeague(region, league);
|
||||||
leaguePositionCache.current[region][league] =
|
leaguePositionCache.current[region][league] = data[0].number - 1;
|
||||||
data.result[0].number - 1;
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
)
|
).flat();
|
||||||
.map(({ result }) => result)
|
|
||||||
.flat();
|
|
||||||
|
|
||||||
useLeaderboardCache.setState(
|
useLeaderboardCache.setState(
|
||||||
produce((draft: LeaderboardCache) => {
|
produce((draft: LeaderboardCache) => {
|
||||||
|
|||||||
+20
-26
@@ -15,6 +15,8 @@ import { REGION_NAMES_SHORT, Region } from '../constants/regions';
|
|||||||
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||||
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
||||||
import getRatingsInfo from '../core/blitz/getRatingsInfo';
|
import getRatingsInfo from '../core/blitz/getRatingsInfo';
|
||||||
|
import { getRatingsLeague } from '../core/blitz/getRatingsLeague';
|
||||||
|
import { getRatingsNeighbors } from '../core/blitz/getRatingsNeighbors';
|
||||||
import regionToRegionSubdomain from '../core/blitz/regionToRegionSubdomain';
|
import regionToRegionSubdomain from '../core/blitz/regionToRegionSubdomain';
|
||||||
import { getArchivedLatestSeasonNumber } from '../core/blitzkrieg/getArchivedLatestSeasonNumber';
|
import { getArchivedLatestSeasonNumber } from '../core/blitzkrieg/getArchivedLatestSeasonNumber';
|
||||||
import getArchivedRatingsInfo from '../core/blitzkrieg/getArchivedRatingsInfo';
|
import getArchivedRatingsInfo from '../core/blitzkrieg/getArchivedRatingsInfo';
|
||||||
@@ -257,11 +259,8 @@ export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
|||||||
const regionSubdomain = regionToRegionSubdomain(region);
|
const regionSubdomain = regionToRegionSubdomain(region);
|
||||||
const result =
|
const result =
|
||||||
subcommandGroup === 'current'
|
subcommandGroup === 'current'
|
||||||
? await fetch(
|
? await getRatingsLeague(region, leagueIndex).then(
|
||||||
`https://${regionSubdomain}.wotblitz.com/en/api/rating-leaderboards/league/${leagueIndex}/top/`,
|
async (result) =>
|
||||||
)
|
|
||||||
.then((response) => response.json() as Promise<LeagueTop>)
|
|
||||||
.then(async ({ result }) =>
|
|
||||||
result.slice(0, limit).map(
|
result.slice(0, limit).map(
|
||||||
(player) =>
|
(player) =>
|
||||||
({
|
({
|
||||||
@@ -272,7 +271,7 @@ export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
|||||||
nickname: player.nickname,
|
nickname: player.nickname,
|
||||||
}) satisfies SimplifiedPlayer,
|
}) satisfies SimplifiedPlayer,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
: await getArchivedRatingsLeaderboard(region, season!).then(
|
: await getArchivedRatingsLeaderboard(region, season!).then(
|
||||||
async (players) => {
|
async (players) => {
|
||||||
const firstPlayerIndex =
|
const firstPlayerIndex =
|
||||||
@@ -338,29 +337,24 @@ export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
|||||||
|
|
||||||
const accountInfo = await getAccountInfo(region, id);
|
const accountInfo = await getAccountInfo(region, id);
|
||||||
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
||||||
const regionSubdomain = regionToRegionSubdomain(region);
|
|
||||||
const neighbors =
|
const neighbors =
|
||||||
subcommandGroup === 'current'
|
subcommandGroup === 'current'
|
||||||
? await fetch(
|
? await getRatingsNeighbors(
|
||||||
`https://${regionSubdomain}.wotblitz.com/en/api/rating-leaderboards/user/${id}/?neighbors=${Math.round(
|
region,
|
||||||
limit / 2,
|
id,
|
||||||
)}`,
|
Math.round(limit / 2),
|
||||||
|
).then((players) =>
|
||||||
|
players.neighbors.map(
|
||||||
|
(player) =>
|
||||||
|
({
|
||||||
|
id: player.spa_id,
|
||||||
|
position: player.number,
|
||||||
|
score: player.score,
|
||||||
|
clan: player.clan_tag,
|
||||||
|
nickname: player.nickname,
|
||||||
|
}) satisfies SimplifiedPlayer,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.then(
|
|
||||||
(response) => response.json() as Promise<RatingsNeighbors>,
|
|
||||||
)
|
|
||||||
.then((players) =>
|
|
||||||
players.neighbors.map(
|
|
||||||
(player) =>
|
|
||||||
({
|
|
||||||
id: player.spa_id,
|
|
||||||
position: player.number,
|
|
||||||
score: player.score,
|
|
||||||
clan: player.clan_tag,
|
|
||||||
nickname: player.nickname,
|
|
||||||
}) satisfies SimplifiedPlayer,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: await getArchivedRatingsLeaderboard(region, season!).then(
|
: await getArchivedRatingsLeaderboard(region, season!).then(
|
||||||
async (players) => {
|
async (players) => {
|
||||||
const playerIndex = players.findIndex(
|
const playerIndex = players.findIndex(
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { LeagueTop } from '../../commands/ratings';
|
import { LeagueTop, RatingsPlayer } from '../../commands/ratings';
|
||||||
import { Region } from '../../constants/regions';
|
import { Region } from '../../constants/regions';
|
||||||
import { context } from '../blitzkrieg/context';
|
import { context } from '../blitzkrieg/context';
|
||||||
import { patientFetch } from '../blitzkrieg/patientFetch';
|
import { patientFetch } from '../blitzkrieg/patientFetch';
|
||||||
@@ -9,7 +9,10 @@ export async function getRatingsLeague(
|
|||||||
league: number,
|
league: number,
|
||||||
usePatientFetcher = false,
|
usePatientFetcher = false,
|
||||||
) {
|
) {
|
||||||
const fetcher = usePatientFetcher ? patientFetch : fetch;
|
const fetcher = (url: string) =>
|
||||||
|
usePatientFetcher
|
||||||
|
? patientFetch(url, undefined, { cache: 'no-store' })
|
||||||
|
: fetch(url, { cache: 'no-store' });
|
||||||
const response = await fetcher(
|
const response = await fetcher(
|
||||||
context === 'website'
|
context === 'website'
|
||||||
? `/api/${region}/ratings/current/league/${league}`
|
? `/api/${region}/ratings/current/league/${league}`
|
||||||
@@ -17,7 +20,9 @@ export async function getRatingsLeague(
|
|||||||
region,
|
region,
|
||||||
)}.wotblitz.com/en/api/rating-leaderboards/league/${league}/top/`,
|
)}.wotblitz.com/en/api/rating-leaderboards/league/${league}/top/`,
|
||||||
);
|
);
|
||||||
const json = (await response.json()) as LeagueTop;
|
const json = await response.json();
|
||||||
|
|
||||||
return json;
|
return context === 'website'
|
||||||
|
? (json as RatingsPlayer[])
|
||||||
|
: (json as LeagueTop).result;
|
||||||
}
|
}
|
||||||
@@ -10,9 +10,10 @@ export async function getRatingsNeighbors(
|
|||||||
count: number,
|
count: number,
|
||||||
usePatientFetcher = false,
|
usePatientFetcher = false,
|
||||||
) {
|
) {
|
||||||
const fetcher = usePatientFetcher
|
const fetcher = (url: string) =>
|
||||||
? patientFetch
|
usePatientFetcher
|
||||||
: (url: string) => fetch(url, { cache: 'no-store' });
|
? patientFetch(url, undefined, { cache: 'no-store' })
|
||||||
|
: fetch(url, { cache: 'no-store' });
|
||||||
const response = await fetcher(
|
const response = await fetcher(
|
||||||
withCORSProxy(
|
withCORSProxy(
|
||||||
`https://${regionToRegionSubdomain(
|
`https://${regionToRegionSubdomain(
|
||||||
|
|||||||
Reference in new issue
Block a user