fix perfs

This commit is contained in:
2023-09-15 19:21:36 +02:00
parent 7d946f49c4
commit d4ded694d6
4 changed files with 32 additions and 13 deletions

View File

@@ -1,6 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { computedAsync, useStorage } from '@vueuse/core'; import { ArrowPathIcon } from '@heroicons/vue/24/outline';
import { ref } from 'vue'; import { useStorage } from '@vueuse/core';
import { onMounted, ref } from 'vue';
import { MarketOrderHistory, MarketResult, getHistory, getHistoryQuartils, jitaId } from "."; import { MarketOrderHistory, MarketResult, getHistory, getHistoryQuartils, jitaId } from ".";
import MarketReultTable from "./MarketResultTable.vue"; import MarketReultTable from "./MarketResultTable.vue";
import { getMarketType, searchMarketType } from "./type"; import { getMarketType, searchMarketType } from "./type";
@@ -12,19 +13,18 @@ type MarketItem = {
const item = ref(""); const item = ref("");
const items = useStorage<MarketItem[]>('market-items', []); const items = useStorage<MarketItem[]>('market-items', []);
const result = computedAsync<MarketResult[]>(() => Promise.all(items.value.map(async (i) => { const result = ref<MarketResult[]>([]);
const [type, quartils] = await Promise.all([ const processResult = async (i: MarketItem) => {
getMarketType(i.typeID), const type = getMarketType(i.typeID);
getHistoryQuartils(i.history) const quartils = getHistoryQuartils(i.history)
]);
return { return {
type, type: await type,
q1: quartils.q1, q1: quartils.q1,
median: quartils.median, median: quartils.median,
q3: quartils.q3 q3: quartils.q3
}; };
})), []); }
const addOrRelaod = async (typeID: number) => { const addOrRelaod = async (typeID: number) => {
const history = await getHistory(jitaId, typeID); const history = await getHistory(jitaId, typeID);
const item = { typeID, history }; const item = { typeID, history };
@@ -34,6 +34,15 @@ const addOrRelaod = async (typeID: number) => {
} else { } else {
items.value = [ ...items.value, item]; items.value = [ ...items.value, item];
} }
const filteredResult = result.value.filter(r => r.type.id !== typeID);
result.value = [ ...filteredResult, await processResult(item) ];
}
const reloadAll = async () => {
items.value = await Promise.all(items.value.map( async i => ({ ...i, history: await getHistory(jitaId, i.typeID) })));
result.value = await Promise.all(items.value.map(processResult));
} }
const addItem = async () => { const addItem = async () => {
const type = await searchMarketType(item.value.split('\t')[0]); const type = await searchMarketType(item.value.split('\t')[0]);
@@ -41,15 +50,19 @@ const addItem = async () => {
item.value = ""; item.value = "";
addOrRelaod(type.id); addOrRelaod(type.id);
} }
onMounted(async () => {
result.value = await Promise.all(items.value.map(processResult));
})
</script> </script>
<template> <template>
<div class="grid mb-2 mt-4"> <div class="grid grid-cols-2 mb-2 mt-4">
<div> <div class="w-auto">
<span>Item: </span> <span>Item: </span>
<input type="text" class="w-96" v-model="item" @keyup.enter="addItem" /> <input type="text" class="w-96" v-model="item" @keyup.enter="addItem" />
<button class="justify-self-end ms-2" @click="addItem">Add</button> <button class="justify-self-end ms-2" @click="addItem">Add</button>
</div> </div>
<button class="justify-self-end flex" @click="reloadAll"><ArrowPathIcon class="h-6 w-6 me-2" />Reload all</button>
</div> </div>
<template v-if="result.length > 0"> <template v-if="result.length > 0">
<hr /> <hr />

View File

@@ -56,7 +56,7 @@ const { sortedArray, headerProps } = useSort(computed(() => props.result.map(r =
<td class="text-right">{{ formatIsk(r.q3) }}</td> <td class="text-right">{{ formatIsk(r.q3) }}</td>
<td class="text-right">{{ percentFormater.format(r.percent) }}</td> <td class="text-right">{{ percentFormater.format(r.percent) }}</td>
<td class="text-right"> <td class="text-right">
<button class="p-0 border-none bg-transparent" @click="$emit('relaod', r.typeID)"><ArrowPathIcon class="h-6 w-6" /></button> <button class="btn-icon" @click="$emit('relaod', r.typeID)"><ArrowPathIcon class="hover:stroke-slate-400"/></button>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View File

@@ -28,7 +28,7 @@ export type HistoryQuartils = {
export const getHistory = async (regionId: number, tyeId: number): Promise<MarketOrderHistory[]> => (await esiAxiosInstance.get(`/markets/${regionId}/history/`, { params: { type_id: tyeId } })).data; export const getHistory = async (regionId: number, tyeId: number): Promise<MarketOrderHistory[]> => (await esiAxiosInstance.get(`/markets/${regionId}/history/`, { params: { type_id: tyeId } })).data;
export const getHistoryQuartils = async (history: MarketOrderHistory[]): Promise<HistoryQuartils> => { export const getHistoryQuartils = (history: MarketOrderHistory[]): HistoryQuartils => {
const volumes = history const volumes = history
.flatMap(h => { .flatMap(h => {
const volume = h.volume; const volume = h.volume;

View File

@@ -41,4 +41,10 @@
@apply bg-slate-600 hover:bg-slate-800; @apply bg-slate-600 hover:bg-slate-800;
border-radius: 5px; border-radius: 5px;
} }
.btn-icon {
@apply p-0 border-none bg-transparent hover:text-slate-400;
> svg {
@apply w-6 h-6 hover:text-slate-400;
}
}
} }