diff options
author | Jacob Schatz <jschatz1@gmail.com> | 2016-03-04 02:15:34 +0000 |
---|---|---|
committer | Jacob Schatz <jschatz1@gmail.com> | 2016-03-04 02:15:34 +0000 |
commit | f8c4dc97230c520df077c1274fd8d88680da5242 (patch) | |
tree | eab481a6661adaaafb82e7be0e9fb591a0c029ed /app/assets | |
parent | f2a9455c388cdd37a212428d9ebcac08459a4f88 (diff) | |
parent | 74d41f89507401fd6be028b36999d16a5111f9ab (diff) | |
download | gitlab-ce-f8c4dc97230c520df077c1274fd8d88680da5242.tar.gz |
Merge branch 'issue_13300' into 'master'
Increase the notes polling timeout over time
Originally by @roperzh at https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/2821
Fixes #13300
See merge request !3071
Diffstat (limited to 'app/assets')
-rw-r--r-- | app/assets/javascripts/notes.js.coffee | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/app/assets/javascripts/notes.js.coffee b/app/assets/javascripts/notes.js.coffee index 82a44cb2b57..c95ead22e6c 100644 --- a/app/assets/javascripts/notes.js.coffee +++ b/app/assets/javascripts/notes.js.coffee @@ -16,10 +16,12 @@ class @Notes @view = view @noteable_url = document.URL @notesCountBadge ||= $(".issuable-details").find(".notes-tab .badge") + @basePollingInterval = 15000 + @maxPollingSteps = 4 @cleanBinding() @addBinding() - @initRefresh() + @setPollingInterval() @setupMainTargetNoteForm() @initTaskList() @@ -91,9 +93,11 @@ class @Notes clearInterval(Notes.interval) Notes.interval = setInterval => @refresh() - , 15000 + , @pollingInterval refresh: -> + return if @refreshing is true + refreshing = true if not document.hidden and document.URL.indexOf(@noteable_url) is 0 @getContent() @@ -105,12 +109,31 @@ class @Notes success: (data) => notes = data.notes @last_fetched_at = data.last_fetched_at + @setPollingInterval(data.notes.length) $.each notes, (i, note) => if note.discussion_with_diff_html? @renderDiscussionNote(note) else @renderNote(note) + always: => + @refreshing = false + + ### + Increase @pollingInterval up to 120 seconds on every function call, + if `shouldReset` has a truthy value, 'null' or 'undefined' the variable + will reset to @basePollingInterval. + Note: this function is used to gradually increase the polling interval + if there aren't new notes coming from the server + ### + setPollingInterval: (shouldReset = true) -> + nthInterval = @basePollingInterval * Math.pow(2, @maxPollingSteps - 1) + if shouldReset + @pollingInterval = @basePollingInterval + else if @pollingInterval < nthInterval + @pollingInterval *= 2 + + @initRefresh() ### Render note in main comments area. |