Commit 3fbdca21 authored by Roberto Dip's avatar Roberto Dip Committed by Alfredo Sumaran

Increase the notes polling timeout over time

A file called notes is loaded every ~15 seconds which checks for
updates to content on the page. This commit increases the polling
timeout over time (15, 30, 60, 120 seconds) and resets
it to 15 seconds if the AJAX call returns new notes

Fixes issue #13300
parent ba869ae5
...@@ -16,10 +16,12 @@ class @Notes ...@@ -16,10 +16,12 @@ class @Notes
@view = view @view = view
@noteable_url = document.URL @noteable_url = document.URL
@notesCountBadge ||= $(".issuable-details").find(".notes-tab .badge") @notesCountBadge ||= $(".issuable-details").find(".notes-tab .badge")
@base_polling_interval = 15000
@limit_polling_interval = 120000
@cleanBinding() @cleanBinding()
@addBinding() @addBinding()
@initRefresh() @setPollingInterval()
@setupMainTargetNoteForm() @setupMainTargetNoteForm()
@initTaskList() @initTaskList()
...@@ -91,7 +93,7 @@ class @Notes ...@@ -91,7 +93,7 @@ class @Notes
clearInterval(Notes.interval) clearInterval(Notes.interval)
Notes.interval = setInterval => Notes.interval = setInterval =>
@refresh() @refresh()
, 15000 , @polling_interval
refresh: -> refresh: ->
if not document.hidden and document.URL.indexOf(@noteable_url) is 0 if not document.hidden and document.URL.indexOf(@noteable_url) is 0
...@@ -105,12 +107,28 @@ class @Notes ...@@ -105,12 +107,28 @@ class @Notes
success: (data) => success: (data) =>
notes = data.notes notes = data.notes
@last_fetched_at = data.last_fetched_at @last_fetched_at = data.last_fetched_at
@setPollingInterval(data.notes.length)
$.each notes, (i, note) => $.each notes, (i, note) =>
if note.discussion_with_diff_html? if note.discussion_with_diff_html?
@renderDiscussionNote(note) @renderDiscussionNote(note)
else else
@renderNote(note) @renderNote(note)
###
Increase @polling_interval up to 120 seconds on every function call,
if `shouldReset` has a truthy value, 'null' or 'undefined' the variable
will reset to @base_polling_interval.
Note: this function is used to gradually increase the polling interval
if there aren't new notes coming from the server
###
setPollingInterval: (shouldReset = true) ->
if shouldReset
@polling_interval = @base_polling_interval
else if @polling_interval < @limit_polling_interval
@polling_interval *= 2
@initRefresh()
### ###
Render note in main comments area. Render note in main comments area.
......
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