diff --git a/lib/routes/bbc/index.js b/lib/routes/bbc/index.js index 73dce7b21..b65377a1d 100644 --- a/lib/routes/bbc/index.js +++ b/lib/routes/bbc/index.js @@ -47,38 +47,40 @@ module.exports = async (ctx) => { } const items = await Promise.all( - feed.items.map(async (item) => { - const response = await got({ - method: 'get', - url: item.link, - }); + feed.items.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const response = await got({ + method: 'get', + url: item.link, + }); - const $ = cheerio.load(response.data); + const $ = cheerio.load(response.data); - let description; + let description; - if (response.request.options.url.pathname.startsWith('/news/av')) { - description = item.content; - } else { - description = utils.ProcessFeed($); - } + if (response.request.options.url.pathname.startsWith('/news/av')) { + description = item.content; + } else { + description = utils.ProcessFeed($); + } - let section = 'sport'; - const urlSplit = item.link.split('/'); - const sectionSplit = urlSplit[urlSplit.length - 1].split('-'); - if (sectionSplit.length > 1) { - section = sectionSplit[0]; - } - section = section[0].toUpperCase() + section.slice(1); + let section = 'sport'; + const urlSplit = item.link.split('/'); + const sectionSplit = urlSplit[urlSplit.length - 1].split('-'); + if (sectionSplit.length > 1) { + section = sectionSplit[0]; + } + section = section[0].toUpperCase() + section.slice(1); - const single = { - title: `[${section}] ${item.title}`, - description, - pubDate: item.pubDate, - link: item.link, - }; - return Promise.resolve(single); - }) + return { + title: `[${section}] ${item.title}`, + description, + pubDate: item.pubDate, + link: item.link, + }; + }) + ) ); ctx.state.data = {