From a2148ecc68a9fe717c44799faaffb4f8933baf85 Mon Sep 17 00:00:00 2001 From: Ryan Lue Date: Fri, 15 Mar 2019 18:36:02 +0800 Subject: [PATCH] Knowledge Base Prep: Backport bugfix for cache key writing race condition in SearchableAjaxSelect --- .../app_post/z_searchable_ajax_select.coffee | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/app/lib/app_post/z_searchable_ajax_select.coffee b/app/assets/javascripts/app/lib/app_post/z_searchable_ajax_select.coffee index 9c3da1044..1176c69cb 100644 --- a/app/assets/javascripts/app/lib/app_post/z_searchable_ajax_select.coffee +++ b/app/assets/javascripts/app/lib/app_post/z_searchable_ajax_select.coffee @@ -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)