From d5dff84c0e0c6ba3fc04d70c8600a8c48e89c592 Mon Sep 17 00:00:00 2001 From: Alexander Drozdov Date: Mon, 31 May 2021 17:52:42 +0300 Subject: [PATCH] partially revert 2a240b5 with setting. closes #388 --- src/ipc/types.ts | 5 +- src/main/config.ts | 7 +++ src/web/overlay/interfaces.ts | 1 + src/web/price-check/trade/TradeListing.vue | 59 ++++++++++++++++++- .../price-check/trade/pathofexile-trade.ts | 13 ++-- src/web/settings/price-check.vue | 19 ++++-- 6 files changed, 88 insertions(+), 16 deletions(-) diff --git a/src/ipc/types.ts b/src/ipc/types.ts index 00c95f48..60cb03fb 100644 --- a/src/ipc/types.ts +++ b/src/ipc/types.ts @@ -62,7 +62,7 @@ type WidgetWellKnownFlag = 'hide-on-focus' export const defaultConfig: Config = { - configVersion: 8, + configVersion: 9, priceCheckKey: 'D', priceCheckKeyHold: 'Ctrl', priceCheckLocked: 'Ctrl + Alt + D', @@ -138,7 +138,8 @@ export const defaultConfig: Config = { wmFlags: ['hide-on-blur', 'skip-menu'], chaosPriceThreshold: 0.05, showRateLimitState: false, - apiLatencySeconds: 2 + apiLatencySeconds: 2, + collapseListings: 'api' } as PriceCheckWidget, { wmId: 3, diff --git a/src/main/config.ts b/src/main/config.ts index e870dbaf..cc2085c7 100644 --- a/src/main/config.ts +++ b/src/main/config.ts @@ -142,6 +142,13 @@ export const config = (() => { config.configVersion = 8 } + if (config.configVersion < 9) { + config.widgets.find(w => w.wmType === 'price-check')! + .collapseListings = 'api' + + config.configVersion = 9 + } + store.store = config return store })() diff --git a/src/web/overlay/interfaces.ts b/src/web/overlay/interfaces.ts index cd0ae389..1212a4a6 100644 --- a/src/web/overlay/interfaces.ts +++ b/src/web/overlay/interfaces.ts @@ -49,6 +49,7 @@ export interface PriceCheckWidget extends Widget { chaosPriceThreshold: number showRateLimitState: boolean apiLatencySeconds: number + collapseListings: 'api' | 'app' } export interface ItemCheckWidget extends Widget { diff --git a/src/web/price-check/trade/TradeListing.vue b/src/web/price-check/trade/TradeListing.vue index e359ff01..8ad8bd99 100644 --- a/src/web/price-check/trade/TradeListing.vue +++ b/src/web/price-check/trade/TradeListing.vue @@ -75,7 +75,7 @@ *** - {{ result.priceAmount }} {{ result.priceCurrency }} + {{ result.priceAmount }} {{ result.priceCurrency }} × {{ result.listedTimes }} {{ result.stackSize }} {{ result.itemLevel }} {{ result.level }} @@ -124,6 +124,9 @@ import { artificialSlowdown } from './artificial-slowdown' const slowdown = artificialSlowdown(900) const SHOW_RESULTS = 20 +const API_FETCH_LIMIT = 100 +const MIN_NOT_GROUPED = 7 +const MIN_GROUPED = 10 function useTradeApi () { let searchId = 0 @@ -131,6 +134,38 @@ function useTradeApi () { const searchResult = shallowRef(null) const fetchResults = shallowRef([]) + const groupedResults = computed(() => { + const out: Array = [] + for (const result of fetchResults.value) { + if (result == null) break + if (out.length === 0) { + out.push({ listedTimes: 1, ...result }) + continue + } + const existingRes = out.find((added, idx) => + ( + added.accountName === result.accountName && + added.priceCurrency === result.priceCurrency && + added.priceAmount === result.priceAmount + ) || + ( + added.accountName === result.accountName && + (out.length - idx) <= 2 // last or prev + ) + ) + if (existingRes) { + if (existingRes.stackSize) { + existingRes.stackSize += result.stackSize! + } else { + existingRes.listedTimes += 1 + } + } else { + out.push({ listedTimes: 1, ...result }) + } + } + return out + }) + async function search (filters: ItemFilters, stats: StatFilter[], item: ParsedItem) { try { searchId += 1 @@ -147,6 +182,7 @@ function useTradeApi () { } searchResult.value = _searchResult + // first two req are parallel, then sequential on demand { const r1 = (_searchResult.result.length > 0) ? requestResults(_searchResult.id, _searchResult.result.slice(0, 10)) @@ -159,12 +195,31 @@ function useTradeApi () { : Promise.resolve() await Promise.all([r1, r2]) } + + let fetched = 20 + async function fetchMore (): Promise { + if (_searchId !== searchId) return + const totalGrouped = groupedResults.value.length + const totalNotGrouped = groupedResults.value.reduce((len, res) => + res.listedTimes <= 2 ? len + 1 : len, 0) + if ( + (totalNotGrouped < MIN_NOT_GROUPED || totalGrouped < MIN_GROUPED) && + fetched < _searchResult.total && + fetched < API_FETCH_LIMIT + ) { + await requestResults(_searchResult.id, _searchResult.result.slice(fetched, fetched + 10)) + .then(results => { _fetchResults.push(...results) }) + fetched += 10 + return fetchMore() + } + } + return fetchMore() } catch (err) { error.value = err.message } } - return { error, searchResult, groupedResults: fetchResults, search } + return { error, searchResult, groupedResults, search } } export default defineComponent({ diff --git a/src/web/price-check/trade/pathofexile-trade.ts b/src/web/price-check/trade/pathofexile-trade.ts index aad8613f..2ef339da 100644 --- a/src/web/price-check/trade/pathofexile-trade.ts +++ b/src/web/price-check/trade/pathofexile-trade.ts @@ -166,7 +166,7 @@ interface TradeRequest { /* eslint-disable camelcase */ heist_trap_disarmament?: FilterRange } } - trade_filters: { + trade_filters?: { filters: { collapse?: FilterBoolean indexed?: { option?: string } @@ -227,13 +227,7 @@ export function createTradeRequest (filters: ItemFilters, stats: StatFilter[], i stats: [ { type: 'and', filters: [] } ], - filters: { - trade_filters: { - filters: { - collapse: { option: 'true' } - } - } - } + filters: {} }, sort: { price: 'asc' @@ -246,6 +240,9 @@ export function createTradeRequest (filters: ItemFilters, stats: StatFilter[], i if (cfg.chaosPriceThreshold !== 0) { prop.set(query.filters, 'trade_filters.filters.price.min', cfg.chaosPriceThreshold) } + if (cfg.collapseListings === 'api') { + prop.set(query.filters, 'trade_filters.filters.collapse.option', String(true)) + } } if (filters.trade.listed) { diff --git a/src/web/settings/price-check.vue b/src/web/settings/price-check.vue index 3c4ca9e7..82afa210 100644 --- a/src/web/settings/price-check.vue +++ b/src/web/settings/price-check.vue @@ -13,7 +13,7 @@ {{ t('Account name') }} {{ t('Last character name') }} -
{{ t('Your items will be highlighted even if it is turned off') }}
+
{{ t('Your items will be highlighted even if this setting is off') }}
{{ t('Fill stat values') }}
@@ -42,9 +42,17 @@ {{ t('No') }}
+
{{ t('Settings below are a compromise between increasing load on PoE website and convenient price checking / more accurate search.') }}
-
{{ t('Extra time to prevent spurious Rate limiting') }}
+
{{ t('Show indication on collapsed listings') }}
+ {{ t('No') }} + {{ t('Yes') }} +
+
+
+
{{ t('Extra time to prevent spurious Rate limiting') }}
+
{{ t('seconds') }} @@ -71,6 +79,7 @@ export default defineComponent({ return { t, config: computed(() => Config.store), + configWidget, searchStatRange: computed({ get () { return Config.store.searchStatRange @@ -114,14 +123,16 @@ export default defineComponent({ "Account name": "Имя учетной записи", "Show seller": "Показывать продавца", "Last character name": "Имя последнего персонажа", - "Your items will be highlighted even if it is turned off": "Ваши предметы будут подсвечены, даже если это отключено", + "Your items will be highlighted even if this setting is off": "Ваши предметы будут подсвечены, даже если эта настройка выключена", "Fill stat values": "Заполнять значения свойств", "Exact roll": "Точное значение", "Show memorized cursor position": "Показывать запомненную позицию курсора", "Minimum buyout price": "Минимальная цена выкупа", "Chaos Orbs": "Сфер хаоса", "Extra time to prevent spurious Rate limiting": "Добавочное время для предотвращения ложного срабатывания ограничения на запросы", - "seconds": "секунды" + "seconds": "секунды", + "Settings below are a compromise between increasing load on PoE website and convenient price checking / more accurate search.": "Настройки ниже являются компромиссом между увеличенной нагрузкой на сайт PoE и удобством проверки цен / более точным поиском.", + "Show indication on collapsed listings": "Показывать индикацию на сгруппированных результатах" } }