Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
Move notification polling interval to remote config (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
piazzatron authored Oct 22, 2020
1 parent 69e7e9b commit 71f8420
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
16 changes: 12 additions & 4 deletions src/containers/notification/store/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,23 @@ import { retrieveCollections } from 'store/cache/collections/utils'
import { retrieveTracks } from 'store/cache/tracks/utils'
import Track from 'models/Track'
import { MessageType } from 'services/native-mobile-interface/types'
import { getRemoteVar, IntKeys } from 'services/remote-config'
import { remoteConfigIntDefaults } from 'services/remote-config/defaults'

const NATIVE_MOBILE = process.env.REACT_APP_NATIVE_MOBILE

// The initial user count to load in for each notification
// NOTE: the rest are loading in in the user list modal
export const USER_INITIAL_LOAD_COUNT = 9

// The interval in ms to poll for new notifications
export const NOTIFICATION_POLLING_INTERVAL = 10000
// Gets the polling interval from remoteconfig
const getPollingIntervalMs = () => {
const pollingInterval = getRemoteVar(IntKeys.NOTIFICATION_POLLING_FREQ_MS)
return (
pollingInterval ??
(remoteConfigIntDefaults[IntKeys.NOTIFICATION_POLLING_FREQ_MS] as number)
)
}

const getTimeAgo = (now: moment.Moment, date: string) => {
const notifDate = moment(date)
Expand Down Expand Up @@ -402,7 +410,7 @@ function* getNotifications(isFirstFetch: boolean) {
)
)
}
yield delay(NOTIFICATION_POLLING_INTERVAL)
yield delay(getPollingIntervalMs())
return
}
const {
Expand Down Expand Up @@ -509,7 +517,7 @@ function* notificationPollingDaemon() {
if (!isBrowserInBackground || isElectron()) {
yield call(getNotifications, isFirstFetch)
}
yield delay(NOTIFICATION_POLLING_INTERVAL)
yield delay(getPollingIntervalMs())
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/services/remote-config/RemoteConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ export enum IntKeys {
/**
* Frequency (in ms) to poll for user wallet balance on the client dashboard page
*/
DASHBOARD_WALLET_BALANCE_POLLING_FREQ_MS = 'DASHBOARD_WALLET_BALANCE_POLLING_FREQ_MS'
DASHBOARD_WALLET_BALANCE_POLLING_FREQ_MS = 'DASHBOARD_WALLET_BALANCE_POLLING_FREQ_MS',

/**
* Frequency (in ms) to poll for notifications from identity service.
*/
NOTIFICATION_POLLING_FREQ_MS = 'NOTIFICATION_POLLING_FREQ_MS'
}

export enum BooleanKeys {
Expand Down
3 changes: 2 additions & 1 deletion src/services/remote-config/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export const remoteConfigIntDefaults: { [key in IntKeys]: number | null } = {
[IntKeys.IMAGE_QUICK_FETCH_TIMEOUT_MS]: 5000,
[IntKeys.IMAGE_QUICK_FETCH_PERFORMANCE_BATCH_SIZE]: 20,
[IntKeys.DISCOVERY_PROVIDER_SELECTION_TIMEOUT_MS]: null,
[IntKeys.DASHBOARD_WALLET_BALANCE_POLLING_FREQ_MS]: 5000
[IntKeys.DASHBOARD_WALLET_BALANCE_POLLING_FREQ_MS]: 5000,
[IntKeys.NOTIFICATION_POLLING_FREQ_MS]: 60 * 1000
}

export const remoteConfigStringDefaults: {
Expand Down

0 comments on commit 71f8420

Please sign in to comment.