mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
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).
This commit is contained in:
@@ -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} の検索結果`,
|
||||
|
||||
@@ -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} の検索結果`,
|
||||
|
||||
Reference in New Issue
Block a user