attempt to fix dupliates in itemIdsToAdd

This commit is contained in:
Nolan Lawson 2018-03-14 09:46:08 -07:00
parent b8d1ccb339
commit a2744cddb0

View file

@ -4,6 +4,8 @@ import { database } from '../_database/database'
import { mark, stop } from '../_utils/marks'
import { store } from '../_store/store'
import { scheduleIdleTask } from '../_utils/scheduleIdleTask'
import uniqBy from 'lodash/uniqBy'
import uniq from 'lodash/uniq'
async function getExistingItemIdsSet (instanceName, timelineName) {
let timelineItemIds = store.getForTimeline(instanceName, timelineName, 'timelineItemIds') || []
@ -28,6 +30,7 @@ async function insertUpdatesIntoTimeline (instanceName, timelineName, updates) {
let itemIdsToAdd = store.getForTimeline(instanceName, timelineName, 'itemIdsToAdd') || []
if (updates && updates.length) {
itemIdsToAdd = itemIdsToAdd.concat(updates.map(_ => _.id))
itemIdsToAdd = uniq(itemIdsToAdd)
console.log('adding ', itemIdsToAdd.length, 'items to itemIdsToAdd')
store.setForTimeline(instanceName, timelineName, {itemIdsToAdd: itemIdsToAdd})
}
@ -78,6 +81,7 @@ const lazilyProcessFreshUpdates = throttle((instanceName, timelineName) => {
export function addStatusOrNotification (instanceName, timelineName, newStatusOrNotification) {
let freshUpdates = store.getForTimeline(instanceName, timelineName, 'freshUpdates') || []
freshUpdates.push(newStatusOrNotification)
freshUpdates = uniqBy(freshUpdates, 'id')
store.setForTimeline(instanceName, timelineName, {freshUpdates: freshUpdates})
lazilyProcessFreshUpdates(instanceName, timelineName)
}