summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Schatz <jschatz@gitlab.com>2016-07-01 14:41:52 +0000
committerJacob Schatz <jschatz@gitlab.com>2016-07-01 14:41:52 +0000
commit6c0d3b4cf3847b78b89170ccb0d8a1e5ebdc48d6 (patch)
tree95686782137afba7fd0d60cda4239ade29b94e1d
parentc578fb064c6a90cbaf60959d7706c0bcc34d87f5 (diff)
parentcc154fc47b4ae2c81d9b8d92d725b4a082ed7727 (diff)
downloadgitlab-ce-6c0d3b4cf3847b78b89170ccb0d8a1e5ebdc48d6.tar.gz
Merge branch 'cache-autocomplete-results' into 'master'
Cache autocomplete results ## What does this MR do? Caches the results of the autocomplete AJAX call to stop new GFM inputs on the page from requesting new data. The cache is then cleared on each new page so that it doesn't stay around per project. See merge request !5043
-rw-r--r--app/assets/javascripts/gfm_auto_complete.js.coffee7
-rw-r--r--app/views/layouts/_init_auto_complete.html.haml1
2 files changed, 6 insertions, 2 deletions
diff --git a/app/assets/javascripts/gfm_auto_complete.js.coffee b/app/assets/javascripts/gfm_auto_complete.js.coffee
index 190bb38504c..b7d040bae85 100644
--- a/app/assets/javascripts/gfm_auto_complete.js.coffee
+++ b/app/assets/javascripts/gfm_auto_complete.js.coffee
@@ -4,7 +4,7 @@ window.GitLab ?= {}
GitLab.GfmAutoComplete =
dataLoading: false
dataLoaded: false
-
+ cachedData: {}
dataSource: ''
# Emoji
@@ -55,7 +55,7 @@ GitLab.GfmAutoComplete =
@setupAtWho()
if @dataSource
- if !@dataLoading
+ if not @dataLoading and not @cachedData
@dataLoading = true
# We should wait until initializations are done
@@ -70,6 +70,8 @@ GitLab.GfmAutoComplete =
@loadData(data)
, 1000)
+ if @cachedData?
+ @loadData(@cachedData)
setupAtWho: ->
# Emoji
@@ -205,6 +207,7 @@ GitLab.GfmAutoComplete =
$.getJSON(dataSource)
loadData: (data) ->
+ @cachedData = data
@dataLoaded = true
# load members
diff --git a/app/views/layouts/_init_auto_complete.html.haml b/app/views/layouts/_init_auto_complete.html.haml
index 96b38485425..12e7ed0e792 100644
--- a/app/views/layouts/_init_auto_complete.html.haml
+++ b/app/views/layouts/_init_auto_complete.html.haml
@@ -3,4 +3,5 @@
- if @noteable
:javascript
GitLab.GfmAutoComplete.dataSource = "#{autocomplete_sources_namespace_project_path(project.namespace, project, type: @noteable.class, type_id: params[:id])}"
+ GitLab.GfmAutoComplete.cachedData = undefined;
GitLab.GfmAutoComplete.setup();