diff --git a/src/app/components/MainGrid.tsx b/src/app/components/MainGrid.tsx index f651cfa..19398d2 100644 --- a/src/app/components/MainGrid.tsx +++ b/src/app/components/MainGrid.tsx @@ -48,7 +48,7 @@ declare module "@mui/material/styles" { } export const MainGrid = () => { - const { characters, updateCharacter } = useContext(CharacterContext); + const { characters } = useContext(CharacterContext); const { compactMode, toggleCompactMode, alertMode, toggleAlertMode, planMode, togglePlanMode, extractionTimeMode, toggleExtractionTimeMode } = useContext(SessionContext); const [accountOrder, setAccountOrder] = useState([]); const [allCollapsed, setAllCollapsed] = useState(false); diff --git a/src/app/page.tsx b/src/app/page.tsx index c46ec11..eda6f72 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -19,6 +19,21 @@ import { EvePraisalResult, fetchAllPrices } from "@/eve-praisal"; import { getPlanet, getPlanetUniverse, getPlanets } from "@/planets"; import { PlanetConfig } from "@/types"; +// Add batch processing utility +const processInBatches = async ( + items: T[], + batchSize: number, + processFn: (item: T) => Promise +): Promise => { + const results: R[] = []; + for (let i = 0; i < items.length; i += batchSize) { + const batch = items.slice(i, i + batchSize); + const batchResults = await Promise.all(batch.map(processFn)); + results.push(...batchResults); + } + return results; +}; + const Home = () => { const searchParams = useSearchParams(); const [characters, setCharacters] = useState([]); @@ -63,15 +78,13 @@ const Home = () => { }; const refreshSession = async (characters: AccessToken[]) => { - return Promise.all( - characters.map((c) => { - try { - return refreshToken(c); - } catch { - return { ...c, needsLogin: true }; - } - }), - ); + return processInBatches(characters, 5, async (c) => { + try { + return await refreshToken(c); + } catch { + return { ...c, needsLogin: true }; + } + }); }; const handleCallback = async ( @@ -107,24 +120,24 @@ const Home = () => { const initializeCharacterPlanets = ( characters: AccessToken[], ): Promise => - Promise.all( - characters.map(async (c) => { - if (c.needsLogin || c.character === undefined) - return { ...c, planets: [] }; - const planets = await getPlanets(c); - const planetsWithInfo: PlanetWithInfo[] = await Promise.all( - planets.map(async (p) => ({ - ...p, - info: await getPlanet(c, p), - infoUniverse: await getPlanetUniverse(p), - })), - ); - return { - ...c, - planets: planetsWithInfo, - }; - }), - ); + processInBatches(characters, 3, async (c) => { + if (c.needsLogin || c.character === undefined) + return { ...c, planets: [] }; + const planets = await getPlanets(c); + const planetsWithInfo: PlanetWithInfo[] = await processInBatches( + planets, + 3, + async (p) => ({ + ...p, + info: await getPlanet(c, p), + infoUniverse: await getPlanetUniverse(p), + }) + ); + return { + ...c, + planets: planetsWithInfo, + }; + }); const saveCharacters = (characters: AccessToken[]): AccessToken[] => { localStorage.setItem("characters", JSON.stringify(characters));