refactor: avoid promise overhead (#8028)

This commit is contained in:
Sukka
2021-08-17 02:45:53 +08:00
committed by GitHub
parent 8053b33b03
commit 6e3b58ed1d
543 changed files with 5295 additions and 5694 deletions

View File

@@ -24,24 +24,23 @@ module.exports = async (ctx) => {
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.title = content('title').text();
item.title = content('title').text();
content('.aside').remove();
content('.aside').remove();
item.description = content('.content').html();
item.pubDate = new Date(content('time').attr('datetime')).toUTCString();
item.description = content('.content').html();
item.pubDate = new Date(content('time').attr('datetime')).toUTCString();
return item;
})
return item;
})
)
);