From 7fc7a62a25d1e9ec95f59e250c1e0e03de266352 Mon Sep 17 00:00:00 2001 From: Yufan You Date: Tue, 9 Dec 2025 20:29:06 +0800 Subject: [PATCH] fix(routes/mercari): set cache max age to routeExpire (#20653) Item description and price may change, and it can be critical to get the latest price, otherwise the item may be bought by others. However, it's still useful to cache the result, as it might be used by other routes (e.g. different keywords or sorting parameters). --- lib/routes/mercari/keyword.ts | 5 ++++- lib/routes/mercari/search.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/routes/mercari/keyword.ts b/lib/routes/mercari/keyword.ts index 50d5f80c1e..bbb7be2bb5 100644 --- a/lib/routes/mercari/keyword.ts +++ b/lib/routes/mercari/keyword.ts @@ -1,3 +1,4 @@ +import { config } from '@/config'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -58,7 +59,9 @@ async function handler(ctx) { const { sort, order, status, keyword } = ctx.req.param(); const statusArray = MercariStatus[status] ? [MercariStatus[status]] : []; const searchItems = (await fetchSearchItems(MercariSort[sort], MercariOrder[order], statusArray, keyword)).items; - const items = await Promise.all(searchItems.map((item) => cache.tryGet(`mercari:${item.id}`, async () => await fetchItemDetail(item.id, item.itemType).then((detail) => formatItemDetail(detail))))); + const items = await Promise.all( + searchItems.map((item) => cache.tryGet(`mercari:${item.id}`, async () => await fetchItemDetail(item.id, item.itemType).then((detail) => formatItemDetail(detail)), config.cache.routeExpire, false)) + ); return { title: `${keyword} の検索結果`, diff --git a/lib/routes/mercari/search.ts b/lib/routes/mercari/search.ts index 69bb153bd5..92232bc18b 100644 --- a/lib/routes/mercari/search.ts +++ b/lib/routes/mercari/search.ts @@ -1,3 +1,4 @@ +import { config } from '@/config'; import type { Route } from '@/types'; import cache from '@/utils/cache'; @@ -87,7 +88,9 @@ async function handler(ctx) { const { keyword, sort, order, status, options } = parseSearchQuery(queryString); const searchItems = (await fetchSearchItems(sort, order, status, keyword, options)).items; - const items = await Promise.all(searchItems.map((item) => cache.tryGet(`mercari:${item.id}`, async () => await fetchItemDetail(item.id, item.itemType).then((detail) => formatItemDetail(detail))))); + const items = await Promise.all( + searchItems.map((item) => cache.tryGet(`mercari:${item.id}`, async () => await fetchItemDetail(item.id, item.itemType).then((detail) => formatItemDetail(detail)), config.cache.routeExpire, false)) + ); return { title: `${keyword} の検索結果`,