From 909a01df0740809d7c45086ef33fb6a43a9223af Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Fri, 4 Nov 2016 15:59:44 +0100 Subject: [PATCH] Fixed issue #349 - ticket search cache issue. --- CHANGES.md | 1 + .../app/lib/app_post/global_search.coffee | 21 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 23399c70a..c14cae677 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,7 @@ # Changes ## Zammad 1.1.0 + - 2016-04-11 Implemented issue#[349](https://github.com/zammad/zammad/issues/349) - ticket search cache issue. - 2016-10-28 Implemented issue#[317](https://github.com/zammad/zammad/issues/317) - Display origin url from tweet/facebook post in article view. ## Zammad 1.0.1 diff --git a/app/assets/javascripts/app/lib/app_post/global_search.coffee b/app/assets/javascripts/app/lib/app_post/global_search.coffee index fdbf37301..66baa1cbf 100644 --- a/app/assets/javascripts/app/lib/app_post/global_search.coffee +++ b/app/assets/javascripts/app/lib/app_post/global_search.coffee @@ -13,15 +13,16 @@ class _globalSearchSingleton extends Spine.Module @apiPath = App.Config.get('api_path') execute: (params) -> - query = params.query - render = params.render - limit = params.limit || 10 + query = params.query + render = params.render + limit = params.limit || 10 + cache_key = query + '_' + limit # use cache for search result - if @searchResultCache[query] - render(@searchResultCache[query].result) - currentTime = new Date - return if @searchResultCache[query].limit is limit && @searchResultCache[query].time > currentTime.setSeconds(currentTime.getSeconds() - 20) + currentTime = new Date + if @searchResultCache[cache_key] && @searchResultCache[cache_key].time > currentTime.setSeconds(currentTime.getSeconds() - 20) + render(@searchResultCache[cache_key].result) + return App.Ajax.request( id: 'search' @@ -48,11 +49,11 @@ class _globalSearchSingleton extends Spine.Module App.Log.error('_globalSearchSingleton', "No such model App.#{item.type}") diff = false - if @searchResultCache[query] - diff = difference(@searchResultCache[query].resultRaw, data.result) + if @searchResultCache[cache_key] + diff = difference(@searchResultCache[cache_key].resultRaw, data.result) # cache search result - @searchResultCache[query] = + @searchResultCache[cache_key] = result: result resultRaw: data.result limit: limit