Skip to content
Snippets Groups Projects
Commit 6c0d3b4c authored by Jacob Schatz's avatar Jacob Schatz
Browse files

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
parents c578fb06 cc154fc4
No related branches found
No related tags found
1 merge request!5043Cache autocomplete results
Pipeline #
Loading
Loading
@@ -4,7 +4,7 @@ window.GitLab ?= {}
GitLab.GfmAutoComplete =
dataLoading: false
dataLoaded: false
cachedData: {}
dataSource: ''
 
# Emoji
Loading
Loading
@@ -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
Loading
Loading
@@ -70,6 +70,8 @@ GitLab.GfmAutoComplete =
@loadData(data)
, 1000)
 
if @cachedData?
@loadData(@cachedData)
 
setupAtWho: ->
# Emoji
Loading
Loading
@@ -205,6 +207,7 @@ GitLab.GfmAutoComplete =
$.getJSON(dataSource)
 
loadData: (data) ->
@cachedData = data
@dataLoaded = true
 
# load members
Loading
Loading
Loading
Loading
@@ -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();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment