diff --git a/src/ui/public/courier/courier.js b/src/ui/public/courier/courier.js index a969f09ad6481..2689f914065c9 100644 --- a/src/ui/public/courier/courier.js +++ b/src/ui/public/courier/courier.js @@ -40,7 +40,7 @@ uiModules.get('kibana/courier').service('courier', ($rootScope, Private) => { class Courier { constructor() { // Listen for refreshInterval changes - $rootScope.$listen(timefilter, 'refreshIntervalUpdate', function () { + const updateRefreshInterval = () => { const refreshIntervalMs = _.get(timefilter.getRefreshInterval(), 'value'); const isRefreshPaused = _.get(timefilter.getRefreshInterval(), 'pause'); @@ -52,7 +52,9 @@ uiModules.get('kibana/courier').service('courier', ($rootScope, Private) => { } else { searchPoll.resume(); } - }); + }; + + $rootScope.$listen(timefilter, 'refreshIntervalUpdate', updateRefreshInterval); const closeOnFatal = _.once(() => { // If there was a fatal error, then stop future searches. We want to use pause instead of @@ -69,6 +71,7 @@ uiModules.get('kibana/courier').service('courier', ($rootScope, Private) => { }); addFatalErrorCallback(closeOnFatal); + updateRefreshInterval(); } /** diff --git a/src/ui/public/timefilter/timefilter.js b/src/ui/public/timefilter/timefilter.js index 1df5473df9611..8f2bbd799efa4 100644 --- a/src/ui/public/timefilter/timefilter.js +++ b/src/ui/public/timefilter/timefilter.js @@ -33,7 +33,7 @@ class Timefilter extends SimpleEmitter { this.isTimeRangeSelectorEnabled = false; this.isAutoRefreshSelectorEnabled = false; this._time = chrome.getUiSettingsClient().get('timepicker:timeDefaults'); - this._refreshInterval = chrome.getUiSettingsClient().get('timepicker:refreshIntervalDefaults'); + this.setRefreshInterval(chrome.getUiSettingsClient().get('timepicker:refreshIntervalDefaults')); } getTime = () => { @@ -79,17 +79,20 @@ class Timefilter extends SimpleEmitter { * @property {boolean} time.pause */ setRefreshInterval = (refreshInterval) => { - // Object.assign used for partially composed updates - const newRefreshInterval = Object.assign(this.getRefreshInterval(), refreshInterval); + const prevRefreshInterval = this.getRefreshInterval(); + const newRefreshInterval = { ...prevRefreshInterval, ...refreshInterval }; + // If the refresh interval is <= 0 handle that as a paused refresh if (newRefreshInterval.value <= 0) { newRefreshInterval.value = 0; newRefreshInterval.pause = true; } - if (areTimePickerValsDifferent(this.getRefreshInterval(), newRefreshInterval)) { - this._refreshInterval = { - value: newRefreshInterval.value, - pause: newRefreshInterval.pause - }; + this._refreshInterval = { + value: newRefreshInterval.value, + pause: newRefreshInterval.pause + }; + // Only send out an event if we already had a previous refresh interval (not for the initial set) + // and the old and new refresh interval are actually different. + if (prevRefreshInterval && areTimePickerValsDifferent(prevRefreshInterval, newRefreshInterval)) { this.emit('refreshIntervalUpdate'); if (!newRefreshInterval.pause && newRefreshInterval.value !== 0) { this.emit('fetch');