From d330d845b1e9feff4bbe690ccb89efcc6b4d9c0f Mon Sep 17 00:00:00 2001 From: "Jocelyn Badgley (Twipped)" Date: Tue, 7 Apr 2020 10:34:39 -0700 Subject: [PATCH] Smarter tweet fetching --- build/page-tweets.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/build/page-tweets.js b/build/page-tweets.js index e697e63..d85ed94 100644 --- a/build/page-tweets.js +++ b/build/page-tweets.js @@ -19,9 +19,10 @@ module.exports = exports = async function tweets (pages) { const tweetsPresent = Object.keys(twitterCache); for (const page of pages) { - if (!page.tweets || !page.tweets.length) continue; + const tweetids = [ ...page.tweets ]; + if (!tweetids.length) continue; - const missing = difference(page.tweets, tweetsPresent); + const missing = difference(uniq(tweetids), tweetsPresent); tweetsNeeded.push(...missing); } @@ -81,9 +82,10 @@ module.exports = exports = async function tweets (pages) { // now loop through pages and substitute the tweet data for the ids for (const page of pages) { - if (!page.tweets || !page.tweets.length) continue; + const tweetids = [ ...page.tweets ]; + if (!tweetids.length) continue; - page.tweets = page.tweets.reduce((dict, tweetid) => { + page.tweets = tweetids.reduce((dict, tweetid) => { attachTweet(dict, tweetid); return dict; }, {});