batching
This commit is contained in:
@@ -19,11 +19,20 @@ const cacheDuration = 1000 * 60 * 5; // 5 minutes
|
||||
export const useApraisalStore = defineStore('appraisal', () => {
|
||||
const cache = ref<Record<number, MarketTypePriceCache>>({});
|
||||
|
||||
const getPricesUncached = async (types: MarketType[]): Promise<MarketTypePrice[]> => (await evepraisalAxiosInstance.post(`/appraisal.json?market=jita&persist=no&raw_textarea=${types.map(t => t.name).join("%0A")}`)).data.appraisal.items.map((item: any) => ({
|
||||
type: types.find(t => t.name === item.typeName),
|
||||
buy: item.prices.buy.max,
|
||||
sell: item.prices.sell.min
|
||||
}));
|
||||
const getPricesUncached = async (types: MarketType[]): Promise<MarketTypePrice[]> => {
|
||||
const batches = [];
|
||||
|
||||
for (let i = 0; i < types.length; i += 100) {
|
||||
batches.push(evepraisalAxiosInstance.post(`/appraisal.json?market=jita&persist=no&raw_textarea=${types.slice(i, i + 100).map(t => t.name).join("%0A")}`));
|
||||
}
|
||||
return (await Promise.all(batches))
|
||||
.flatMap(b => b.data.appraisal.items)
|
||||
.map((item: any) => ({
|
||||
type: types.find(t => t.name === item.typeName) as MarketType,
|
||||
buy: item.prices.buy.max,
|
||||
sell: item.prices.sell.min
|
||||
}));
|
||||
}
|
||||
|
||||
const getPrice = async (type: MarketType): Promise<MarketTypePrice> => (await getPrices([type]))[0];
|
||||
const getPrices = async (types: MarketType[]): Promise<MarketTypePrice[]> => {
|
||||
|
||||
@@ -30,7 +30,7 @@ const open = (t: MarketType, s?: Record<string, number> | number) => {
|
||||
}
|
||||
modalOpen.value = true;
|
||||
}
|
||||
const add = () => {
|
||||
const add = () => {
|
||||
const id = type.value?.id;
|
||||
|
||||
if (!id) {
|
||||
|
||||
Reference in New Issue
Block a user