diff --git a/lib/routes/3dm/game.js b/lib/routes/3dm/game.js index 4bbca45166ac..a7e28aeccaf7 100644 --- a/lib/routes/3dm/game.js +++ b/lib/routes/3dm/game.js @@ -23,25 +23,18 @@ module.exports = async (ctx) => { .get(); } - const items = await Promise.all( - list.map(async (i) => { - const item = $(i); - const url = item.find('.bt').attr('href'); + const items = list.map((i) => { + const item = $(i); + const url = item.find('.bt').attr('href'); - const cache = await ctx.cache.get(url); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } - const single = { - title: item.find('.bt').text(), - pubDate: item.find('p').text(), - link: url, - guid: url, - }; - ctx.cache.set(url, JSON.stringify(single)); - return Promise.resolve(single); - }) - ); + const single = { + title: item.find('.bt').text(), + pubDate: item.find('p').text(), + link: url, + guid: url, + }; + return single; + }); ctx.state.data = { title: $('title') diff --git a/lib/routes/allpoetry/order.js b/lib/routes/allpoetry/order.js index 766dcc3213dd..c9027f7db1a8 100644 --- a/lib/routes/allpoetry/order.js +++ b/lib/routes/allpoetry/order.js @@ -16,40 +16,31 @@ module.exports = async (ctx) => { const $ = cheerio.load(data); - const items = await Promise.all( - $('.sub') - .slice(0, 5) - .get() - .map(async (e) => { - let itemUrl = $(e) + const items = $('.sub') + .get() + .map((e) => { + let itemUrl = $(e) + .find('h1.title > a') + .attr('href'); + + itemUrl = url.resolve(host, itemUrl); + + const single = { + title: $(e) .find('h1.title > a') - .attr('href'); - - itemUrl = url.resolve(host, itemUrl); - - const cache = await ctx.cache.get(itemUrl); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } - - const single = { - title: $(e) - .find('h1.title > a') - .text(), - description: $(e) - .find('div.poem_body') - .html(), - link: itemUrl, - author: $(e) - .find('div.bio >a ') - .attr('data-name'), - guid: itemUrl, - }; - - ctx.cache.set(itemUrl, JSON.stringify(single)); - return Promise.resolve(single); - }) - ); + .text(), + description: $(e) + .find('div.poem_body') + .html(), + link: itemUrl, + author: $(e) + .find('div.bio >a ') + .attr('data-name'), + guid: itemUrl, + }; + + return single; + }); ctx.state.data = { title: `All Poetry - ${order.toUpperCase() + order.slice(1)}`, diff --git a/lib/routes/douban/topic.js b/lib/routes/douban/topic.js index 7c76b9fc92b0..b796057af857 100644 --- a/lib/routes/douban/topic.js +++ b/lib/routes/douban/topic.js @@ -64,7 +64,9 @@ module.exports = async (ctx) => { description: description, }; - ctx.cache.set(link, JSON.stringify(single)); + if (type !== 'status') { + ctx.cache.set(link, JSON.stringify(single)); + } return Promise.resolve(single); }) ); diff --git a/lib/routes/duozhi/index.js b/lib/routes/duozhi/index.js index 6efd8a968f2d..cbf7b5c4fb91 100644 --- a/lib/routes/duozhi/index.js +++ b/lib/routes/duozhi/index.js @@ -25,15 +25,14 @@ module.exports = async (ctx) => { description: '', }; - const description_key = 'duozhi_description_' + guid; - const description_value = await ctx.cache.get(description_key); + const key = 'duozhi_' + guid; + const cache = await ctx.cache.get(key); - const pubDate_key = 'duozhi_pubDate_' + guid; - const pubDate_value = await ctx.cache.get(pubDate_key); + if (cache) { + const value = JSON.parse(cache); - if (description_value && pubDate_value) { - single.description = description_value; - single.pubDate = pubDate_value; + single.description = value.description; + single.pubDate = value.pubDate; } else { const temp = await got(link); single.description = $(temp.data) @@ -47,8 +46,10 @@ module.exports = async (ctx) => { .substr(0, 18) ).toUTCString(); - ctx.cache.set(description_key, single.description); - ctx.cache.set(pubDate_key, single.pubDate); + ctx.cache.set(key, { + description: single.description, + pubDate: single.pubDate, + }); } return Promise.resolve(single); diff --git a/lib/routes/zhibo8/forum.js b/lib/routes/zhibo8/forum.js index c03b02d7e5e2..6c5270faf22c 100644 --- a/lib/routes/zhibo8/forum.js +++ b/lib/routes/zhibo8/forum.js @@ -40,7 +40,7 @@ module.exports = async (ctx) => { $img.attr('src', 'https:' + src); }); single.description = $('.detail_ent').html(); - ctx.cache.set(key, single.description, 12 * 60 * 60); + ctx.cache.set(key, single.description); } return Promise.resolve(single); })