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
This commit is contained in:
Christopher Gurnee 2021-11-01 17:57:46 -04:00
parent 157fd7104f
commit 47b4d913bd

View file

@ -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...')