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 { getIdsThatTheseStatusesReblogged } from './statuses'
import { database } from '../_database/database'
import { mark, stop } from '../_utils/marks'
import { store } from '../_store/store'
@ -7,34 +6,32 @@ import { scheduleIdleTask } from '../_utils/scheduleIdleTask'
import uniqBy from 'lodash/uniqBy'
import uniq from 'lodash/uniq'
async function getExistingItemIdsSet (instanceName, timelineName) {
function getExistingItemIdsSet (instanceName, timelineName) {
let timelineItemIds = store.getForTimeline(instanceName, timelineName, 'timelineItemIds') || []
if (timelineName === 'notifications') {
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
let existingItemIds = await getExistingItemIdsSet(instanceName, timelineName)
let existingItemIds = getExistingItemIdsSet(instanceName, timelineName)
return updates.filter(update => !existingItemIds.has(update.id))
}
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)
let itemIdsToAdd = store.getForTimeline(instanceName, timelineName, 'itemIdsToAdd') || []
if (updates && updates.length) {
itemIdsToAdd = itemIdsToAdd.concat(updates.map(_ => _.id))
itemIdsToAdd = uniq(itemIdsToAdd)
itemIdsToAdd = uniq(itemIdsToAdd.concat(updates.map(_ => _.id)))
console.log('adding ', itemIdsToAdd.length, 'items to itemIdsToAdd')
store.setForTimeline(instanceName, timelineName, {itemIdsToAdd: itemIdsToAdd})
}
}
async function insertUpdatesIntoThreads (instanceName, updates) {
if (!updates.length) {