This commit is contained in:
2024-05-24 21:22:28 +02:00
parent a7b1fb902c
commit 9f2627faf8
8 changed files with 115 additions and 29 deletions

View File

@@ -1,4 +1,6 @@
import { esiAxiosInstance } from "@/service";
import { RegionalMarketCache } from '../RegionalMarketCache';
import { jitaId } from "../market";
export type EsiMarketOrderHistory = {
@@ -11,16 +13,18 @@ export type EsiMarketOrderHistory = {
}
// TODO use pinia store
const historyCache: Record<number, Record<number, EsiMarketOrderHistory[]>> = {};
const historyCache: RegionalMarketCache<EsiMarketOrderHistory[]> = new RegionalMarketCache(() => {
const date = new Date();
export const getHistory = async (regionId: number, tyeId: number): Promise<EsiMarketOrderHistory[]> => {
if (historyCache[regionId]?.[tyeId]) {
return historyCache[regionId][tyeId];
if (date.getUTCHours() < 11) {
date.setUTCDate(date.getUTCDate() - 1);
}
date.setUTCHours(11, 0, 0, 0);
return date;
});
const value = (await esiAxiosInstance.get(`/markets/${regionId}/history/`, { params: { type_id: tyeId } })).data;
export const getHistory = async (tyeId: number, regionId?: number): Promise<EsiMarketOrderHistory[]> => {
const rId = regionId ?? jitaId;
historyCache[regionId] = historyCache[regionId] ?? {};
historyCache[regionId][tyeId] = value;
return value;
return historyCache.computeIfAbsent(rId, tyeId, async () => (await esiAxiosInstance.get(`/markets/${rId}/history/`, { params: { type_id: tyeId } })).data);
}