From a2744cddb0a9a5682a798f009e260b52ecce453f Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Wed, 14 Mar 2018 09:46:08 -0700 Subject: [PATCH] attempt to fix dupliates in itemIdsToAdd --- routes/_actions/addStatusOrNotification.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/routes/_actions/addStatusOrNotification.js b/routes/_actions/addStatusOrNotification.js index c774a1f0..419d9827 100644 --- a/routes/_actions/addStatusOrNotification.js +++ b/routes/_actions/addStatusOrNotification.js @@ -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) }