Fixed issue#466 - Search result is not shown if you search for "AAA", "BBB" and "AAA" again.
This commit is contained in:
parent
f2a2b9efe9
commit
550b963ad0
1 changed files with 22 additions and 19 deletions
|
@ -9,7 +9,8 @@ class App.GlobalSearch
|
||||||
class _globalSearchSingleton extends Spine.Module
|
class _globalSearchSingleton extends Spine.Module
|
||||||
|
|
||||||
constructor: ->
|
constructor: ->
|
||||||
@searchResultCache = {}
|
@searchResultCache = undefined
|
||||||
|
@searchResultCacheByKey = {}
|
||||||
@apiPath = App.Config.get('api_path')
|
@apiPath = App.Config.get('api_path')
|
||||||
|
|
||||||
execute: (params) ->
|
execute: (params) ->
|
||||||
|
@ -20,8 +21,8 @@ class _globalSearchSingleton extends Spine.Module
|
||||||
|
|
||||||
# use cache for search result
|
# use cache for search result
|
||||||
currentTime = new Date
|
currentTime = new Date
|
||||||
if @searchResultCache[cacheKey] && @searchResultCache[cacheKey].time > currentTime.setSeconds(currentTime.getSeconds() - 20)
|
if @searchResultCacheByKey[cacheKey] && @searchResultCacheByKey[cacheKey].time > currentTime.setSeconds(currentTime.getSeconds() - 20)
|
||||||
render(@searchResultCache[cacheKey].result)
|
@renderTry(render, @searchResultCacheByKey[cacheKey].result, cacheKey)
|
||||||
return
|
return
|
||||||
|
|
||||||
App.Ajax.request(
|
App.Ajax.request(
|
||||||
|
@ -31,7 +32,7 @@ class _globalSearchSingleton extends Spine.Module
|
||||||
data:
|
data:
|
||||||
query: query
|
query: query
|
||||||
limit: limit
|
limit: limit
|
||||||
processData: true,
|
processData: true
|
||||||
success: (data, status, xhr) =>
|
success: (data, status, xhr) =>
|
||||||
App.Collection.loadAssets(data.assets)
|
App.Collection.loadAssets(data.assets)
|
||||||
result = {}
|
result = {}
|
||||||
|
@ -48,19 +49,21 @@ class _globalSearchSingleton extends Spine.Module
|
||||||
else
|
else
|
||||||
App.Log.error('_globalSearchSingleton', "No such model App.#{item.type}")
|
App.Log.error('_globalSearchSingleton', "No such model App.#{item.type}")
|
||||||
|
|
||||||
diff = false
|
@renderTry(render, result, cacheKey)
|
||||||
if @searchResultCache[cacheKey]
|
|
||||||
diff = difference(@searchResultCache[cacheKey].resultRaw, data.result)
|
|
||||||
|
|
||||||
# cache search result
|
|
||||||
@searchResultCache[cacheKey] =
|
|
||||||
result: result
|
|
||||||
resultRaw: data.result
|
|
||||||
limit: limit
|
|
||||||
time: new Date
|
|
||||||
|
|
||||||
# if result hasn't changed, do not rerender
|
|
||||||
return if diff isnt false && _.isEmpty(diff)
|
|
||||||
|
|
||||||
render(result)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
renderTry: (render, result, cacheKey) =>
|
||||||
|
|
||||||
|
# if result hasn't changed, do not rerender
|
||||||
|
diff = false
|
||||||
|
if @searchResultCache
|
||||||
|
diff = difference(@searchResultCache, result)
|
||||||
|
return if diff isnt false && _.isEmpty(diff)
|
||||||
|
|
||||||
|
# cache search result
|
||||||
|
@searchResultCache = result
|
||||||
|
@searchResultCacheByKey[cacheKey] =
|
||||||
|
result: result
|
||||||
|
time: new Date
|
||||||
|
|
||||||
|
render(result)
|
||||||
|
|
Loading…
Reference in a new issue