diff --git a/lib/routes/apnews/topics.ts b/lib/routes/apnews/topics.ts index bd89c1ba353a7b..a4f65f319d7c4c 100644 --- a/lib/routes/apnews/topics.ts +++ b/lib/routes/apnews/topics.ts @@ -1,7 +1,7 @@ import { Route, ViewType } from '@/types'; import got from '@/utils/got'; import { load } from 'cheerio'; -import { fetchArticle, removeDuplicateByKey } from './utils'; +import { asyncPoolAll, fetchArticle, removeDuplicateByKey } from './utils'; const HOME_PAGE = 'https://apnews.com'; export const route: Route = { @@ -41,17 +41,16 @@ async function handler(ctx) { const response = await got(url); const $ = load(response.data); - const items = await Promise.all( - $(':is(.PagePromo-content, .PageListStandardE-leadPromo-info) bsp-custom-headline') - .toArray() - .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : Infinity) - .map((e) => ({ - title: $(e).find('span.PagePromoContentIcons-text').text(), - link: $(e).find('a').attr('href'), - })) - .filter((e) => typeof e.link === 'string') - .map((item) => (ctx.req.query('fulltext') === 'true' ? fetchArticle(item) : item)) - ); + const list = $(':is(.PagePromo-content, .PageListStandardE-leadPromo-info) bsp-custom-headline') + .toArray() + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : Infinity) + .map((e) => ({ + title: $(e).find('span.PagePromoContentIcons-text').text(), + link: $(e).find('a').attr('href'), + })) + .filter((e) => typeof e.link === 'string'); + + const items = ctx.req.query('fulltext') === 'true' ? await asyncPoolAll(10, list, (item) => fetchArticle(item)) : list; return { title: $('title').text(),