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