Knowledge Base Prep: Backport bugfix for cache key writing race condition in SearchableAjaxSelect

This commit is contained in:
Ryan Lue 2019-03-15 18:36:02 +08:00 committed by Thorsten Eckel
parent 48352ece6d
commit a2148ecc68

View file

@ -13,11 +13,11 @@ class App.SearchableAjaxSelect extends App.SearchableSelect
# create cache and cache key
@searchResultCache = @searchResultCache || {}
@cacheKey = "#{objectString}+#{@query}"
cacheKey = "#{objectString}+#{@query}"
# use cache for search result
if @searchResultCache[@cacheKey]
return @onAjaxResponse( @searchResultCache[@cacheKey] )
if @searchResultCache[cacheKey]
return @renderResponse( @searchResultCache[cacheKey] )
# add timeout for loader icon
clearTimeout @loaderTimeoutId
@ -32,18 +32,18 @@ class App.SearchableAjaxSelect extends App.SearchableSelect
query: @query
limit: @options.attribute.limit
processData: true
success: @onAjaxResponse
success: (data, status, xhr) =>
# cache search result
@searchResultCache[cacheKey] = data
@renderResponse(data)
)
onAjaxResponse: (data, status, xhr) =>
renderResponse: (data) =>
# clear timout and remove loader icon
clearTimeout @loaderTimeoutId
@el.removeClass('is-loading')
# cache search result
@searchResultCache[@cacheKey] = data
# load assets
App.Collection.loadAssets(data.assets)