From a25b7f19cc8e403ffd7856e631cde7e9df63f1cc Mon Sep 17 00:00:00 2001 From: Jef LeCompte Date: Fri, 9 Apr 2021 13:34:49 -0400 Subject: [PATCH] refactor: simplify maxPrice logic Ref: 9b02c36370aaf7fef20a90b2427273c2f7b30f00, #2057 --- src/store/lookup.ts | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/src/store/lookup.ts b/src/store/lookup.ts index 6d53f78afe..640cc4055a 100644 --- a/src/store/lookup.ts +++ b/src/store/lookup.ts @@ -407,26 +407,6 @@ async function checkIsCloudflare(store: Store, page: Page, link: Link) { return false; } -async function isAboveMaxPrice( - store: Store, - page: Page, - link: Link, - options: Selector -): Promise { - if (store.labels.maxPrice) { - const maxPrice = config.store.maxPrice.series[link.series]; - - link.price = await getPrice(page, store.labels.maxPrice, options); - - if (link.price && link.price > maxPrice && maxPrice > 0) { - logger.info(Print.maxPrice(link, store, maxPrice, true)); - return true; - } - } - - return false; -} - async function isItemInStock(store: Store, page: Page, link: Link) { const baseOptions: Selector = { requireVisible: false, @@ -469,10 +449,6 @@ async function isItemInStock(store: Store, page: Page, link: Link) { logger.info(Print.outOfStock(link, store, true)); return false; } - - if (await isAboveMaxPrice(store, page, link, options)) { - return false; - } } if (store.labels.inStock) { @@ -486,8 +462,15 @@ async function isItemInStock(store: Store, page: Page, link: Link) { logger.info(Print.outOfStock(link, store, true)); return false; } + } - if (await isAboveMaxPrice(store, page, link, options)) { + if (store.labels.maxPrice) { + const maxPrice = config.store.maxPrice.series[link.series]; + + link.price = await getPrice(page, store.labels.maxPrice, baseOptions); + + if (link.price && link.price > maxPrice && maxPrice > 0) { + logger.info(Print.maxPrice(link, store, maxPrice, true)); return false; } }