don't attempt to remove reblogged duplicates

This commit is contained in:
Nolan Lawson 2018-03-18 09:31:36 -07:00
parent 4d386357e7
commit 536fa97060
1 changed files with 13 additions and 16 deletions

View File

@ -1,5 +1,4 @@
import throttle from 'lodash/throttle' import throttle from 'lodash/throttle'
import { getIdsThatTheseStatusesReblogged } from './statuses'
import { database } from '../_database/database' import { database } from '../_database/database'
import { mark, stop } from '../_utils/marks' import { mark, stop } from '../_utils/marks'
import { store } from '../_store/store' import { store } from '../_store/store'
@ -7,33 +6,31 @@ import { scheduleIdleTask } from '../_utils/scheduleIdleTask'
import uniqBy from 'lodash/uniqBy' import uniqBy from 'lodash/uniqBy'
import uniq from 'lodash/uniq' import uniq from 'lodash/uniq'
async function getExistingItemIdsSet (instanceName, timelineName) { function getExistingItemIdsSet (instanceName, timelineName) {
let timelineItemIds = store.getForTimeline(instanceName, timelineName, 'timelineItemIds') || [] let timelineItemIds = store.getForTimeline(instanceName, timelineName, 'timelineItemIds') || []
if (timelineName === 'notifications') { return new Set(timelineItemIds)
return new Set(timelineItemIds)
}
let reblogIds = await getIdsThatTheseStatusesReblogged(instanceName, timelineItemIds)
return new Set([].concat(timelineItemIds).concat(reblogIds))
} }
async function removeDuplicates (instanceName, timelineName, updates) { function removeDuplicates (instanceName, timelineName, updates) {
// remove duplicates, including duplicates due to reblogs // remove duplicates, including duplicates due to reblogs
let existingItemIds = await getExistingItemIdsSet(instanceName, timelineName) let existingItemIds = getExistingItemIdsSet(instanceName, timelineName)
return updates.filter(update => !existingItemIds.has(update.id)) return updates.filter(update => !existingItemIds.has(update.id))
} }
async function insertUpdatesIntoTimeline (instanceName, timelineName, updates) { async function insertUpdatesIntoTimeline (instanceName, timelineName, updates) {
updates = await removeDuplicates(instanceName, timelineName, updates) updates = removeDuplicates(instanceName, timelineName, updates)
if (!updates.length) {
return
}
await database.insertTimelineItems(instanceName, timelineName, updates) await database.insertTimelineItems(instanceName, timelineName, updates)
let itemIdsToAdd = store.getForTimeline(instanceName, timelineName, 'itemIdsToAdd') || [] let itemIdsToAdd = store.getForTimeline(instanceName, timelineName, 'itemIdsToAdd') || []
if (updates && updates.length) {
itemIdsToAdd = itemIdsToAdd.concat(updates.map(_ => _.id)) itemIdsToAdd = uniq(itemIdsToAdd.concat(updates.map(_ => _.id)))
itemIdsToAdd = uniq(itemIdsToAdd) console.log('adding ', itemIdsToAdd.length, 'items to itemIdsToAdd')
console.log('adding ', itemIdsToAdd.length, 'items to itemIdsToAdd') store.setForTimeline(instanceName, timelineName, {itemIdsToAdd: itemIdsToAdd})
store.setForTimeline(instanceName, timelineName, {itemIdsToAdd: itemIdsToAdd})
}
} }
async function insertUpdatesIntoThreads (instanceName, updates) { async function insertUpdatesIntoThreads (instanceName, updates) {