perf(route/baobua): cache paginated content to reduce API requests

This commit is contained in:
AiraNadih
2025-04-03 00:49:35 +00:00
parent a97ee175b7
commit 200616c15a
+7 -2
View File
@@ -1,4 +1,5 @@
import { load } from 'cheerio';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
@@ -32,8 +33,12 @@ async function loadArticle(link) {
const additionalContents = await Promise.all(
Array.from({ length: totalPages - 1 }, async (_, i) => {
try {
const response = await got(`${link}?page=${i + 2}`);
const pageDom = load(response.body);
const url = `${link}?page=${i + 2}`;
const html = await cache.tryGet(url, async () => {
const response = await got(url);
return response.body;
});
const pageDom = load(typeof html === 'string' ? html : '');
return pageDom('.contentme2').html() ?? '';
} catch {
return '';