mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-25 03:29:51 +01:00
feat: removed swr caching
This commit is contained in:
1 parent
9e6343a111
commit
c742c0725d
3 files changed
+31
-24
No files matched your search
@@ -49,7 +49,6 @@
|
|||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-fuzzysort": "^1.0.1",
|
"react-fuzzysort": "^1.0.1",
|
||||||
"satori": "^0.10.8",
|
"satori": "^0.10.8",
|
||||||
"swr": "^2.2.4",
|
|
||||||
"vite-node": "^0.34.5",
|
"vite-node": "^0.34.5",
|
||||||
"vitepress": "^1.0.0-rc.20",
|
"vitepress": "^1.0.0-rc.20",
|
||||||
"vitepress-plugin-auto-sidebar": "^1.1.0",
|
"vitepress-plugin-auto-sidebar": "^1.1.0",
|
||||||
|
|||||||
@@ -13,10 +13,9 @@ import {
|
|||||||
import { produce } from 'immer';
|
import { produce } from 'immer';
|
||||||
import { debounce, range } from 'lodash';
|
import { debounce, range } from 'lodash';
|
||||||
import { ChangeEvent, useEffect, useRef, useState } from 'react';
|
import { ChangeEvent, useEffect, useRef, useState } from 'react';
|
||||||
import useSWR from 'swr';
|
|
||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
import { BlitzkriegRatingsLeaderboardEntry } from '../../../../scripts/buildRatingsLeaderboard';
|
import { BlitzkriegRatingsLeaderboardEntry } from '../../../../scripts/buildRatingsLeaderboard';
|
||||||
import { RatingsPlayer } from '../../../commands/ratings';
|
import { RatingsInfo, RatingsPlayer } from '../../../commands/ratings';
|
||||||
import * as Leaderboard from '../../../components/Leaderboard';
|
import * as Leaderboard from '../../../components/Leaderboard';
|
||||||
import PageWrapper from '../../../components/PageWrapper';
|
import PageWrapper from '../../../components/PageWrapper';
|
||||||
import { LEAGUES } from '../../../constants/leagues';
|
import { LEAGUES } from '../../../constants/leagues';
|
||||||
@@ -50,6 +49,7 @@ type PlayersCache = Record<
|
|||||||
Region,
|
Region,
|
||||||
Record<number, Record<number, BlitzkriegRatingsLeaderboardEntry>>
|
Record<number, Record<number, BlitzkriegRatingsLeaderboardEntry>>
|
||||||
>;
|
>;
|
||||||
|
type InfoCache = Record<Region, Record<number, RatingsInfo | undefined>>;
|
||||||
|
|
||||||
const useNameCache = create<NameCache>(() => ({
|
const useNameCache = create<NameCache>(() => ({
|
||||||
asia: {},
|
asia: {},
|
||||||
@@ -61,6 +61,11 @@ const usePlayersCache = create<PlayersCache>(() => ({
|
|||||||
com: {},
|
com: {},
|
||||||
eu: {},
|
eu: {},
|
||||||
}));
|
}));
|
||||||
|
const useInfoCache = create<InfoCache>(() => ({
|
||||||
|
asia: {},
|
||||||
|
com: {},
|
||||||
|
eu: {},
|
||||||
|
}));
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
const [region, setRegion] = useState<Region>('com');
|
const [region, setRegion] = useState<Region>('com');
|
||||||
@@ -80,17 +85,10 @@ export default function Page() {
|
|||||||
{ type: 'id'; id: number } | { type: 'position'; position: number } | null
|
{ type: 'id'; id: number } | { type: 'position'; position: number } | null
|
||||||
>(null);
|
>(null);
|
||||||
|
|
||||||
const { data: ratingsInfo } = useSWR(
|
const ratingsInfo = useInfoCache()[region][season];
|
||||||
`ratings-info-${region}-${season}`,
|
const [latestArchivedSeasonNumber, setLatestArchivedSeasonNumber] = useState<
|
||||||
() =>
|
number | null
|
||||||
season === 0
|
>(null);
|
||||||
? getRatingsInfo(region)
|
|
||||||
: getArchivedRatingsInfo(region, season),
|
|
||||||
);
|
|
||||||
const { data: latestArchivedSeasonNumber } = useSWR<number>(
|
|
||||||
getArchivedLatestSeasonNumber.name,
|
|
||||||
getArchivedLatestSeasonNumber,
|
|
||||||
);
|
|
||||||
|
|
||||||
const names = useNameCache();
|
const names = useNameCache();
|
||||||
const players = usePlayersCache();
|
const players = usePlayersCache();
|
||||||
@@ -107,6 +105,18 @@ export default function Page() {
|
|||||||
// page reset on season or region change
|
// page reset on season or region change
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setPage(0);
|
setPage(0);
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const newInfo =
|
||||||
|
season === 0
|
||||||
|
? await getRatingsInfo(region)
|
||||||
|
: await getArchivedRatingsInfo(region, season);
|
||||||
|
useInfoCache.setState(
|
||||||
|
produce((draft: InfoCache) => {
|
||||||
|
draft[region][season] = newInfo;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
})();
|
||||||
}, [season, region]);
|
}, [season, region]);
|
||||||
// initial leagues caching for current season
|
// initial leagues caching for current season
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -235,6 +245,12 @@ export default function Page() {
|
|||||||
ratingsInfo?.detail,
|
ratingsInfo?.detail,
|
||||||
players[region][season] !== undefined && 0 in players[region][season],
|
players[region][season] !== undefined && 0 in players[region][season],
|
||||||
]);
|
]);
|
||||||
|
// latest archived season number caching
|
||||||
|
useEffect(() => {}, [
|
||||||
|
getArchivedLatestSeasonNumber().then((result) => {
|
||||||
|
setLatestArchivedSeasonNumber(result);
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
async function cacheNeighbors(
|
async function cacheNeighbors(
|
||||||
id: number,
|
id: number,
|
||||||
|
|||||||
@@ -2518,7 +2518,7 @@ clean-stack@^2.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b"
|
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b"
|
||||||
integrity sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==
|
integrity sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==
|
||||||
|
|
||||||
[email protected], client-only@^0.0.1:
|
[email protected]:
|
||||||
version "0.0.1"
|
version "0.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/client-only/-/client-only-0.0.1.tgz#38bba5d403c41ab150bff64a95c85013cf73bca1"
|
resolved "https://registry.yarnpkg.com/client-only/-/client-only-0.0.1.tgz#38bba5d403c41ab150bff64a95c85013cf73bca1"
|
||||||
integrity sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==
|
integrity sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==
|
||||||
@@ -4302,14 +4302,6 @@ supports-color@^7.1.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
has-flag "^4.0.0"
|
has-flag "^4.0.0"
|
||||||
|
|
||||||
swr@^2.2.4:
|
|
||||||
version "2.2.4"
|
|
||||||
resolved "https://registry.yarnpkg.com/swr/-/swr-2.2.4.tgz#03ec4c56019902fbdc904d78544bd7a9a6fa3f07"
|
|
||||||
integrity sha512-njiZ/4RiIhoOlAaLYDqwz5qH/KZXVilRLvomrx83HjzCWTfa+InyfAjv05PSFxnmLzZkNO9ZfvgoqzAaEI4sGQ==
|
|
||||||
dependencies:
|
|
||||||
client-only "^0.0.1"
|
|
||||||
use-sync-external-store "^1.2.0"
|
|
||||||
|
|
||||||
tabbable@^6.2.0:
|
tabbable@^6.2.0:
|
||||||
version "6.2.0"
|
version "6.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/tabbable/-/tabbable-6.2.0.tgz#732fb62bc0175cfcec257330be187dcfba1f3b97"
|
resolved "https://registry.yarnpkg.com/tabbable/-/tabbable-6.2.0.tgz#732fb62bc0175cfcec257330be187dcfba1f3b97"
|
||||||
@@ -4470,7 +4462,7 @@ use-sidecar@^1.1.2:
|
|||||||
detect-node-es "^1.1.0"
|
detect-node-es "^1.1.0"
|
||||||
tslib "^2.0.0"
|
tslib "^2.0.0"
|
||||||
|
|
||||||
[email protected], use-sync-external-store@^1.2.0:
|
[email protected]:
|
||||||
version "1.2.0"
|
version "1.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz#7dbefd6ef3fe4e767a0cf5d7287aacfb5846928a"
|
resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz#7dbefd6ef3fe4e767a0cf5d7287aacfb5846928a"
|
||||||
integrity sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==
|
integrity sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==
|
||||||
|
|||||||
Reference in new issue
Block a user