be less aggressive about throttling notifications

This commit is contained in:
Nolan Lawson 2018-04-02 18:00:45 -07:00
parent 3458c353e4
commit cfb8e28fcc
2 changed files with 5 additions and 6 deletions

View File

@ -5,6 +5,7 @@ import { store } from '../_store/store'
import { scheduleIdleTask } from '../_utils/scheduleIdleTask' 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'
import { isMobile } from '../_utils/isMobile'
function getExistingItemIdsSet (instanceName, timelineName) { function getExistingItemIdsSet (instanceName, timelineName) {
let timelineItemIds = store.getForTimeline(instanceName, timelineName, 'timelineItemIds') || [] let timelineItemIds = store.getForTimeline(instanceName, timelineName, 'timelineItemIds') || []
@ -70,10 +71,11 @@ async function processFreshUpdates (instanceName, timelineName) {
} }
const lazilyProcessFreshUpdates = throttle((instanceName, timelineName) => { const lazilyProcessFreshUpdates = throttle((instanceName, timelineName) => {
scheduleIdleTask(() => { const runTask = isMobile() ? scheduleIdleTask : requestAnimationFrame
runTask(() => {
/* no await */ processFreshUpdates(instanceName, timelineName) /* no await */ processFreshUpdates(instanceName, timelineName)
}) })
}, 5000) }, 3000)
export function addStatusOrNotification (instanceName, timelineName, newStatusOrNotification) { export function addStatusOrNotification (instanceName, timelineName, newStatusOrNotification) {
addStatusesOrNotifications(instanceName, timelineName, [newStatusOrNotification]) addStatusesOrNotifications(instanceName, timelineName, [newStatusOrNotification])

View File

@ -1,5 +1,4 @@
import { TimelineStream } from '../_api/TimelineStream' import { TimelineStream } from '../_api/TimelineStream'
import { scheduleIdleTask } from '../_utils/scheduleIdleTask'
import { mark, stop } from '../_utils/marks' import { mark, stop } from '../_utils/marks'
import { deleteStatus } from './deleteStatuses' import { deleteStatus } from './deleteStatuses'
import { addStatusOrNotification } from './addStatusOrNotification' import { addStatusOrNotification } from './addStatusOrNotification'
@ -29,9 +28,7 @@ export function createStream (streamingApi, instanceName, accessToken,
console.error("don't know how to handle event", msg) console.error("don't know how to handle event", msg)
return return
} }
scheduleIdleTask(() => {
processMessage(instanceName, timelineName, msg) processMessage(instanceName, timelineName, msg)
})
}, },
onOpen () { onOpen () {
if (onOpenStream) { if (onOpenStream) {