market types from mammon

This commit is contained in:
Sirttas
2026-06-13 16:30:31 +02:00
parent 3a35d2181d
commit 16078cc62b
5 changed files with 184 additions and 55 deletions
+11 -11
View File
@@ -1,15 +1,15 @@
import { defineStore } from 'pinia';
import { RegionalMarketCache } from '../RegionalMarketCache';
import { jitaId } from '../market';
import { MarketType } from "../type";
import { MarketTypePrice } from './MarketTypePrice';
import { getMammonPrices } from './mammon';
import {defineStore} from 'pinia';
import {RegionalMarketCache} from '../RegionalMarketCache';
import {jitaId} from '../market';
import {MarketType} from "../type";
import {MarketTypePrice} from './MarketTypePrice';
import {getMammonPrices} from './mammon';
const cacheDuration = 1000 * 60 * 5; // 5 minutes
const batchSize = 100;
const CACHE_DURATION = 1000 * 60 * 5; // 5 minutes
const BATCH_SIZE = 100;
export const useApraisalStore = defineStore('appraisal', () => {
const cache: RegionalMarketCache<MarketTypePrice> = new RegionalMarketCache(cacheDuration);
const cache: RegionalMarketCache<MarketTypePrice> = new RegionalMarketCache(CACHE_DURATION);
const getPricesUncached = getMammonPrices;
@@ -32,8 +32,8 @@ export const useApraisalStore = defineStore('appraisal', () => {
if (uncached.length > 0) {
const batches: Promise<MarketTypePrice[]>[] = [];
for (let i = 0; i < uncached.length; i += batchSize) {
batches.push(getPricesUncached(uncached.slice(i, i + batchSize)));
for (let i = 0; i < uncached.length; i += BATCH_SIZE) {
batches.push(getPricesUncached(uncached.slice(i, i + BATCH_SIZE)));
}
const prices = (await Promise.all(batches)).flat();
+18 -43
View File
@@ -1,30 +1,23 @@
import {esiAxiosInstance} from '@/service';
import {marketApi} from '@/mammon/mammonService';
import type {MarketTypeResponse} from '@/generated/mammon';
export type MarketType = {
id: number;
group_id: number;
market_group_id: number;
name: string;
published: boolean;
description: string;
base_price: number;
icon_id: number;
volume: number;
portion_size: number;
}
export type MarketType = MarketTypeResponse;
const cache = new Map<number, MarketType>(); // TODO move to pinia store
const fetchType = (id: number): Promise<MarketType> => {
if (cache.has(id)) {
return Promise.resolve(cache.get(id)!);
const BATCH_SIZE = 100;
const fetchTypes = async (ids: number[]): Promise<void> => {
const missing = ids.filter(id => !cache.has(id));
if (missing.length === 0) {
return;
}
return esiAxiosInstance.get<Omit<MarketType, 'id'> & { type_id: number }>(`/universe/types/${id}/`).then(r => {
const { type_id, ...rest } = r.data;
const marketType: MarketType = { id: type_id, ...rest };
cache.set(id, marketType);
return marketType;
});
const batches: Promise<MarketType[]>[] = [];
for (let i = 0; i < missing.length; i += BATCH_SIZE) {
batches.push(marketApi.findTypes(missing.slice(i, i + BATCH_SIZE)).then(r => r.data));
}
const results = await Promise.all(batches);
results.flat().forEach(t => cache.set(t.id, t));
};
export const getMarketType = async (type: string | number): Promise<MarketType> => (await getMarketTypes([type]))[0];
@@ -33,28 +26,10 @@ export const getMarketTypes = async (types: (string | number)[]): Promise<Market
return [];
}
const ids = types.filter((t): t is number => typeof t === 'number');
return Promise.all(ids.map(fetchType));
await fetchTypes(ids);
return ids.map(id => cache.get(id)).filter((t): t is MarketType => t !== undefined);
}
const blueprintMarketGroups = [ // TODO add all groups
2,
2157,
2159,
2339,
2160,
211,
1016,
339,
2290,
357,
1530,
359,
1531,
1532,
1533,
358
]
export const searchMarketTypes = async (search: string): Promise<MarketType[]> => {
export const searchMarketTypes = async (_search: string): Promise<MarketType[]> => {
return []
}
+1 -1
View File
@@ -89,7 +89,7 @@ watchEffect(async () => {
<template>
<div @click="() => isOpen = true" v-on-click-outside="() => isOpen = false">
<div class="fake-input">
<img v-if="modelValue?.type_id" :src="`https://images.evetech.net/types/${modelValue.type_id}/icon?size=32`" alt="" />
<img v-if="modelValue?.id" :src="`https://images.evetech.net/types/${modelValue.id}/icon?size=32`" alt="" />
<input type="text" v-model="name" @keyup.enter="submit" @keyup.down="moveDown" @keyup.up="moveUp" />
</div>
<div v-if="suggestions.length > 1" class="z-20 absolute w-96">