Skip to content

Commit 7875795

Browse files
authored
fix(route/news): use p-map to limit concurrency (#18927)
1 parent 4b0215d commit 7875795

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

lib/routes/anthropic/news.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import ofetch from '@/utils/ofetch';
22
import { load } from 'cheerio';
33
import cache from '@/utils/cache';
44
import { Route } from '@/types';
5+
import pMap from 'p-map';
56

67
export const route: Route = {
78
path: '/news',
@@ -39,8 +40,9 @@ async function handler() {
3940
};
4041
});
4142

42-
const out = await Promise.all(
43-
list.map((item) =>
43+
const out = await pMap(
44+
list,
45+
(item) =>
4446
cache.tryGet(item.link, async () => {
4547
const response = await ofetch(item.link);
4648
const $ = load(response);
@@ -62,8 +64,8 @@ async function handler() {
6264
item.description = content.html();
6365

6466
return item;
65-
})
66-
)
67+
}),
68+
{ concurrency: 5 }
6769
);
6870

6971
return {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"oauth-1.0a": "2.2.6",
108108
"ofetch": "1.4.1",
109109
"otplib": "12.0.1",
110+
"p-map": "7.0.3",
110111
"pac-proxy-agent": "7.2.0",
111112
"proxy-chain": "2.5.8",
112113
"puppeteer": "22.6.2",

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)