diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /app/assets/javascripts/notes/stores/actions.js | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'app/assets/javascripts/notes/stores/actions.js')
-rw-r--r-- | app/assets/javascripts/notes/stores/actions.js | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/app/assets/javascripts/notes/stores/actions.js b/app/assets/javascripts/notes/stores/actions.js index bdb85360be8..086e9122c60 100644 --- a/app/assets/javascripts/notes/stores/actions.js +++ b/app/assets/javascripts/notes/stores/actions.js @@ -12,6 +12,7 @@ import loadAwardsHandler from '../../awards_handler'; import { deprecatedCreateFlash as Flash } from '../../flash'; import { isInViewport, scrollToElement, isInMRPage } from '../../lib/utils/common_utils'; import Poll from '../../lib/utils/poll'; +import { create } from '../../lib/utils/recurrence'; import { mergeUrlParams } from '../../lib/utils/url_utility'; import sidebarTimeTrackingEventHub from '../../sidebar/event_hub'; import TaskList from '../../task_list'; @@ -21,6 +22,7 @@ import eventHub from '../event_hub'; import * as types from './mutation_types'; import * as utils from './utils'; +const NOTES_POLLING_INTERVAL = 6000; let eTagPoll; export const updateLockedAttribute = ({ commit, getters }, { locked, fullPath }) => { @@ -469,6 +471,19 @@ const getFetchDataParams = (state) => { }; export const poll = ({ commit, state, getters, dispatch }) => { + const notePollOccurrenceTracking = create(); + let flashContainer; + + notePollOccurrenceTracking.handle(1, () => { + // Since polling halts internally after 1 failure, we manually try one more time + setTimeout(() => eTagPoll.restart(), NOTES_POLLING_INTERVAL); + }); + notePollOccurrenceTracking.handle(2, () => { + // On the second failure in a row, show the alert and try one more time (hoping to succeed and clear the error) + flashContainer = Flash(__('Something went wrong while fetching latest comments.')); + setTimeout(() => eTagPoll.restart(), NOTES_POLLING_INTERVAL); + }); + eTagPoll = new Poll({ resource: { poll: () => { @@ -477,8 +492,15 @@ export const poll = ({ commit, state, getters, dispatch }) => { }, }, method: 'poll', - successCallback: ({ data }) => pollSuccessCallBack(data, commit, state, getters, dispatch), - errorCallback: () => Flash(__('Something went wrong while fetching latest comments.')), + successCallback: ({ data }) => { + pollSuccessCallBack(data, commit, state, getters, dispatch); + + if (notePollOccurrenceTracking.count) { + notePollOccurrenceTracking.reset(); + } + flashContainer?.close(); + }, + errorCallback: () => notePollOccurrenceTracking.occur(), }); if (!Visibility.hidden()) { |