mirror of
https://github.com/calli-eve/eve-pi.git
synced 2026-02-16 12:39:51 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
499cb40d3a | ||
|
|
470935fe9d | ||
|
|
7ce238c9c7 | ||
|
|
6523000e69 |
@@ -4,7 +4,7 @@ Simple tool to track your PI planet extractors. Login with your characters and e
|
|||||||
|
|
||||||
Any questions, feedback or suggestions are welcome at [EVE PI Discord](https://discord.gg/bCdXzU8PHK)
|
Any questions, feedback or suggestions are welcome at [EVE PI Discord](https://discord.gg/bCdXzU8PHK)
|
||||||
|
|
||||||
## [Avanto hosted PI tool](https://pi.avanto.tk)
|
## [Hosted PI tool](https://pi.calli.fi)
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|
|||||||
@@ -48,7 +48,7 @@ declare module "@mui/material/styles" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const MainGrid = () => {
|
export const MainGrid = () => {
|
||||||
const { characters, updateCharacter } = useContext(CharacterContext);
|
const { characters } = useContext(CharacterContext);
|
||||||
const { compactMode, toggleCompactMode, alertMode, toggleAlertMode, planMode, togglePlanMode, extractionTimeMode, toggleExtractionTimeMode } = useContext(SessionContext);
|
const { compactMode, toggleCompactMode, alertMode, toggleAlertMode, planMode, togglePlanMode, extractionTimeMode, toggleExtractionTimeMode } = useContext(SessionContext);
|
||||||
const [accountOrder, setAccountOrder] = useState<string[]>([]);
|
const [accountOrder, setAccountOrder] = useState<string[]>([]);
|
||||||
const [allCollapsed, setAllCollapsed] = useState(false);
|
const [allCollapsed, setAllCollapsed] = useState(false);
|
||||||
|
|||||||
@@ -19,6 +19,21 @@ import { EvePraisalResult, fetchAllPrices } from "@/eve-praisal";
|
|||||||
import { getPlanet, getPlanetUniverse, getPlanets } from "@/planets";
|
import { getPlanet, getPlanetUniverse, getPlanets } from "@/planets";
|
||||||
import { PlanetConfig } from "@/types";
|
import { PlanetConfig } from "@/types";
|
||||||
|
|
||||||
|
// Add batch processing utility
|
||||||
|
const processInBatches = async <T, R>(
|
||||||
|
items: T[],
|
||||||
|
batchSize: number,
|
||||||
|
processFn: (item: T) => Promise<R>
|
||||||
|
): Promise<R[]> => {
|
||||||
|
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 Home = () => {
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const [characters, setCharacters] = useState<AccessToken[]>([]);
|
const [characters, setCharacters] = useState<AccessToken[]>([]);
|
||||||
@@ -63,15 +78,13 @@ const Home = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const refreshSession = async (characters: AccessToken[]) => {
|
const refreshSession = async (characters: AccessToken[]) => {
|
||||||
return Promise.all(
|
return processInBatches(characters, 50, async (c) => {
|
||||||
characters.map((c) => {
|
try {
|
||||||
try {
|
return await refreshToken(c);
|
||||||
return refreshToken(c);
|
} catch {
|
||||||
} catch {
|
return { ...c, needsLogin: true };
|
||||||
return { ...c, needsLogin: true };
|
}
|
||||||
}
|
});
|
||||||
}),
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCallback = async (
|
const handleCallback = async (
|
||||||
@@ -107,24 +120,24 @@ const Home = () => {
|
|||||||
const initializeCharacterPlanets = (
|
const initializeCharacterPlanets = (
|
||||||
characters: AccessToken[],
|
characters: AccessToken[],
|
||||||
): Promise<AccessToken[]> =>
|
): Promise<AccessToken[]> =>
|
||||||
Promise.all(
|
processInBatches(characters, 50, async (c) => {
|
||||||
characters.map(async (c) => {
|
if (c.needsLogin || c.character === undefined)
|
||||||
if (c.needsLogin || c.character === undefined)
|
return { ...c, planets: [] };
|
||||||
return { ...c, planets: [] };
|
const planets = await getPlanets(c);
|
||||||
const planets = await getPlanets(c);
|
const planetsWithInfo: PlanetWithInfo[] = await processInBatches(
|
||||||
const planetsWithInfo: PlanetWithInfo[] = await Promise.all(
|
planets,
|
||||||
planets.map(async (p) => ({
|
3,
|
||||||
...p,
|
async (p) => ({
|
||||||
info: await getPlanet(c, p),
|
...p,
|
||||||
infoUniverse: await getPlanetUniverse(p),
|
info: await getPlanet(c, p),
|
||||||
})),
|
infoUniverse: await getPlanetUniverse(p),
|
||||||
);
|
})
|
||||||
return {
|
);
|
||||||
...c,
|
return {
|
||||||
planets: planetsWithInfo,
|
...c,
|
||||||
};
|
planets: planetsWithInfo,
|
||||||
}),
|
};
|
||||||
);
|
});
|
||||||
|
|
||||||
const saveCharacters = (characters: AccessToken[]): AccessToken[] => {
|
const saveCharacters = (characters: AccessToken[]): AccessToken[] => {
|
||||||
localStorage.setItem("characters", JSON.stringify(characters));
|
localStorage.setItem("characters", JSON.stringify(characters));
|
||||||
|
|||||||
@@ -22,10 +22,51 @@ export const getPlanets = async (character: AccessToken): Promise<Planet[]> => {
|
|||||||
return planets;
|
return planets;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface CachedPlanetData {
|
||||||
|
data: PlanetInfo;
|
||||||
|
timestamp: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CACHE_DURATION_MS = 60_000; // 1 minute
|
||||||
|
const CACHE_STORAGE_KEY = "planet_cache";
|
||||||
|
|
||||||
|
const loadCacheFromStorage = (): Map<string, CachedPlanetData> => {
|
||||||
|
try {
|
||||||
|
const stored = localStorage.getItem(CACHE_STORAGE_KEY);
|
||||||
|
if (stored) {
|
||||||
|
const parsed = JSON.parse(stored);
|
||||||
|
return new Map(Object.entries(parsed));
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to load planet cache from localStorage:", error);
|
||||||
|
}
|
||||||
|
return new Map();
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveCacheToStorage = (cache: Map<string, CachedPlanetData>) => {
|
||||||
|
try {
|
||||||
|
const obj = Object.fromEntries(cache);
|
||||||
|
localStorage.setItem(CACHE_STORAGE_KEY, JSON.stringify(obj));
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to save planet cache to localStorage:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const planetCache = loadCacheFromStorage();
|
||||||
|
|
||||||
export const getPlanet = async (
|
export const getPlanet = async (
|
||||||
character: AccessToken,
|
character: AccessToken,
|
||||||
planet: Planet,
|
planet: Planet,
|
||||||
): Promise<PlanetInfo> => {
|
): Promise<PlanetInfo> => {
|
||||||
|
const cacheKey = `${character.character.characterId}-${planet.planet_id}`;
|
||||||
|
const cached = planetCache.get(cacheKey);
|
||||||
|
|
||||||
|
if (cached && Date.now() - cached.timestamp < CACHE_DURATION_MS) {
|
||||||
|
console.log(`[Cache HIT] Planet ${planet.planet_id} for character ${character.character.characterId}`);
|
||||||
|
return cached.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`[Cache MISS] Fetching planet ${planet.planet_id} for character ${character.character.characterId}`);
|
||||||
const api = new Api();
|
const api = new Api();
|
||||||
const planetInfo = (
|
const planetInfo = (
|
||||||
await api.v3.getCharactersCharacterIdPlanetsPlanetId(
|
await api.v3.getCharactersCharacterIdPlanetsPlanetId(
|
||||||
@@ -36,6 +77,15 @@ export const getPlanet = async (
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
).data;
|
).data;
|
||||||
|
|
||||||
|
planetCache.set(cacheKey, {
|
||||||
|
data: planetInfo,
|
||||||
|
timestamp: Date.now(),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Persist to localStorage
|
||||||
|
saveCacheToStorage(planetCache);
|
||||||
|
|
||||||
return planetInfo;
|
return planetInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user