Commit c2d16177 authored by Phil Hughes's avatar Phil Hughes

Change polling interval for merge request widget

Uses the header value returned by the widget endpoint
to determine what the initial starting polling interval is.
For closed or merged merge requests this interval
is longer.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/232478
parent 9bac264b
......@@ -7,6 +7,7 @@ import stateMaps from 'ee_else_ce/vue_merge_request_widget/stores/state_maps';
import { sprintf, s__, __ } from '~/locale';
import Project from '~/pages/projects/project';
import SmartInterval from '~/smart_interval';
import { secondsToMilliseconds } from '~/lib/utils/datetime_utility';
import { deprecatedCreateFlash as createFlash } from '../flash';
import mergeRequestQueryVariablesMixin from './mixins/merge_request_query_variables';
import Loading from './components/loading.vue';
......@@ -202,7 +203,10 @@ export default {
},
mounted() {
MRWidgetService.fetchInitialData()
.then(({ data }) => this.initWidget(data))
.then(({ data, headers }) => {
this.startingPollInterval = Number(headers['POLL-INTERVAL']);
this.initWidget(data);
})
.catch(() =>
createFlash(__('Unable to load the merge request widget. Try reloading the page.')),
);
......@@ -292,9 +296,10 @@ export default {
initPolling() {
this.pollingInterval = new SmartInterval({
callback: this.checkStatus,
startingInterval: 10 * 1000,
maxInterval: 240 * 1000,
hiddenInterval: window.gon?.features?.widgetVisibilityPolling && 360 * 1000,
startingInterval: this.startingPollInterval,
maxInterval: this.startingPollInterval + secondsToMilliseconds(4 * 60),
hiddenInterval:
window.gon?.features?.widgetVisibilityPolling && secondsToMilliseconds(6 * 60),
incrementByFactorOf: 2,
});
},
......
import { normalizeHeaders } from '~/lib/utils/common_utils';
import axios from '../../lib/utils/axios_utils';
export default class MRWidgetService {
......@@ -82,6 +83,11 @@ export default class MRWidgetService {
return Promise.all([
axios.get(window.gl.mrWidgetData.merge_request_cached_widget_path),
axios.get(window.gl.mrWidgetData.merge_request_widget_path),
]).then(axios.spread((res, cachedRes) => ({ data: Object.assign(res.data, cachedRes.data) })));
]).then(
axios.spread((res, cachedRes) => ({
data: Object.assign(res.data, cachedRes.data),
headers: normalizeHeaders(res.headers),
})),
);
}
}
---
title: Increase widget polling for closed and merged merge requests
merge_request:
author:
type: changed
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment