history cache

This commit is contained in:
2024-05-22 09:59:13 +02:00
parent e379f490a4
commit f75156bc62
9 changed files with 37 additions and 25 deletions

View File

@@ -0,0 +1,26 @@
import { esiAxiosInstance } from "@/service";
export type EsiMarketOrderHistory = {
average: number;
date: string;
highest: number;
lowest: number;
order_count: number;
volume: number;
}
// TODO use pinia store
const historyCache: { [key: number]: { [key: number]: EsiMarketOrderHistory[] } } = {};
export const getHistory = async (regionId: number, tyeId: number): Promise<EsiMarketOrderHistory[]> => {
if (historyCache[regionId]?.[tyeId]) {
return historyCache[regionId][tyeId];
}
const value = (await esiAxiosInstance.get(`/markets/${regionId}/history/`, { params: { type_id: tyeId } })).data;
historyCache[regionId] = historyCache[regionId] ?? {};
historyCache[regionId][tyeId] = value;
return value;
}