summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Dip <dip.jesusr@gmail.com>2016-02-15 16:09:55 -0300
committerAlfredo Sumaran <alfredo@gitlab.com>2016-03-03 15:20:00 -0500
commit3fbdca214c355d9b7bab9cdf00ad3546d96c267e (patch)
treef9c5eae20737a3c8ebac2ae3c2508e25d861c5cf
parentba869ae50d0c43867f7d34a4f7e08520c1e4c7f1 (diff)
downloadgitlab-ce-3fbdca214c355d9b7bab9cdf00ad3546d96c267e.tar.gz
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
-rw-r--r--app/assets/javascripts/notes.js.coffee22
1 files changed, 20 insertions, 2 deletions
diff --git a/app/assets/javascripts/notes.js.coffee b/app/assets/javascripts/notes.js.coffee
index 82a44cb2b57..b3073d082de 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")
+ @base_polling_interval = 15000
+ @limit_polling_interval = 120000
@cleanBinding()
@addBinding()
- @initRefresh()
+ @setPollingInterval()
@setupMainTargetNoteForm()
@initTaskList()
@@ -91,7 +93,7 @@ class @Notes
clearInterval(Notes.interval)
Notes.interval = setInterval =>
@refresh()
- , 15000
+ , @polling_interval
refresh: ->
if not document.hidden and document.URL.indexOf(@noteable_url) is 0
@@ -105,12 +107,28 @@ 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)
+ ###
+ 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.