fix(route/news): use p-map to limit concurrency (#18927)
This commit is contained in:
parent
4b0215d29d
commit
78757950aa
|
|
@ -2,6 +2,7 @@ import ofetch from '@/utils/ofetch';
|
|||
import { load } from 'cheerio';
|
||||
import cache from '@/utils/cache';
|
||||
import { Route } from '@/types';
|
||||
import pMap from 'p-map';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/news',
|
||||
|
|
@ -39,8 +40,9 @@ async function handler() {
|
|||
};
|
||||
});
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map((item) =>
|
||||
const out = await pMap(
|
||||
list,
|
||||
(item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
const response = await ofetch(item.link);
|
||||
const $ = load(response);
|
||||
|
|
@ -62,8 +64,8 @@ async function handler() {
|
|||
item.description = content.html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
}),
|
||||
{ concurrency: 5 }
|
||||
);
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -107,6 +107,7 @@
|
|||
"oauth-1.0a": "2.2.6",
|
||||
"ofetch": "1.4.1",
|
||||
"otplib": "12.0.1",
|
||||
"p-map": "7.0.3",
|
||||
"pac-proxy-agent": "7.2.0",
|
||||
"proxy-chain": "2.5.8",
|
||||
"puppeteer": "22.6.2",
|
||||
|
|
|
|||
|
|
@ -188,6 +188,9 @@ importers:
|
|||
otplib:
|
||||
specifier: 12.0.1
|
||||
version: 12.0.1
|
||||
p-map:
|
||||
specifier: 7.0.3
|
||||
version: 7.0.3
|
||||
pac-proxy-agent:
|
||||
specifier: 7.2.0
|
||||
version: 7.2.0
|
||||
|
|
@ -5053,6 +5056,10 @@ packages:
|
|||
resolution: {integrity: sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
p-map@7.0.3:
|
||||
resolution: {integrity: sha512-VkndIv2fIB99swvQoA65bm+fsmt6UNdGeIB0oxBs+WhAhdh08QA04JXpI7rbB9r08/nkbysKoya9rtDERYOYMA==}
|
||||
engines: {node: '>=18'}
|
||||
|
||||
pac-proxy-agent@7.2.0:
|
||||
resolution: {integrity: sha512-TEB8ESquiLMc0lV8vcd5Ql/JAKAoyzHFXaStwjkzpOpC5Yv+pIzLfHvjTSdf3vpa2bMiUQrg9i6276yn8666aA==}
|
||||
engines: {node: '>= 14'}
|
||||
|
|
@ -11546,6 +11553,8 @@ snapshots:
|
|||
dependencies:
|
||||
p-limit: 3.1.0
|
||||
|
||||
p-map@7.0.3: {}
|
||||
|
||||
pac-proxy-agent@7.2.0:
|
||||
dependencies:
|
||||
'@tootallnate/quickjs-emscripten': 0.23.0
|
||||
|
|
|
|||
Loading…
Reference in New Issue