cache
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user