From 47b4d913bd6f75dcb67c4f23f0377a6dce5acfe0 Mon Sep 17 00:00:00 2001 From: Christopher Gurnee Date: Mon, 1 Nov 2021 17:57:46 -0400 Subject: [PATCH] Fix small bug introduced in 20eae33 Duplicate comments were being retrieved from Reddit under certain uncommon circumstances, this also caused the comment counts to be off --- src/pages/thread/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pages/thread/index.js b/src/pages/thread/index.js index 1ea3cc7..70dfbd0 100644 --- a/src/pages/thread/index.js +++ b/src/pages/thread/index.js @@ -54,14 +54,19 @@ class Thread extends React.Component { console.log(`Pushshift: ${pushshiftComments.length} comments`) const pushshiftCommentLookup = new Map(pushshiftComments.map(c => [c.id, c])) const ids = [] + const missingIds = new Set() // Extract ids from pushshift response pushshiftComments.forEach(comment => { ids.push(comment.id) - if (comment.parent_id != threadID && !pushshiftCommentLookup.has(comment.parent_id)) { + if (comment.parent_id != threadID && + !pushshiftCommentLookup.has(comment.parent_id) && + !missingIds.has(comment.parent_id)) { ids.push(comment.parent_id) + missingIds.add(comment.parent_id) } }); + missingIds.clear() // Get all the comments from reddit this.props.global.setLoading('Comparing comments to Reddit API...')