fix(route/gnn): remove empty div, limit concurrency (#19912)
This commit is contained in:
parent
8139a648e3
commit
54dae2a0e4
|
|
@ -4,6 +4,7 @@ import got from '@/utils/got';
|
|||
import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
import pMap from 'p-map';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/gnn/:category?',
|
||||
|
|
@ -94,6 +95,8 @@ async function handler(ctx) {
|
|||
const list = $('div.BH-lbox.GN-lbox2')
|
||||
.children()
|
||||
.not('p,a,img,span')
|
||||
// <div data-news-id="291265" id="291265"></div>
|
||||
.not('[data-news-id]')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
|
|
@ -116,8 +119,9 @@ async function handler(ctx) {
|
|||
};
|
||||
});
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
const items = await pMap(
|
||||
list,
|
||||
async (item) => {
|
||||
item.description = await cache.tryGet(item.link, async () => {
|
||||
const response = await got.get(item.link);
|
||||
let component = '';
|
||||
|
|
@ -163,7 +167,8 @@ async function handler(ctx) {
|
|||
return component;
|
||||
});
|
||||
return item;
|
||||
})
|
||||
},
|
||||
{ concurrency: 5 }
|
||||
);
|
||||
|
||||
return {
|
||||
|
|
|
|||
Loading…
Reference in New Issue