From f5db9ea1dc8d23dff732dd3345bf85798d64f1e9 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 6 Jun 2015 06:18:35 +0100 Subject: Re-work completions: initial refactor. The original completion-engine interface was based on three functions. With some experience, it seems there is a pattern involving explicit regular expressions which is used by all actual engine implementations. This is a refactoring to make those regular expressions explicit (and required), and is a first step towards adding additional fucntionality. This also simplifies the completion cache key (use JSON instead of some weird hash). --- background_scripts/completion_search.coffee | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'background_scripts/completion_search.coffee') diff --git a/background_scripts/completion_search.coffee b/background_scripts/completion_search.coffee index d89eb278..cb819025 100644 --- a/background_scripts/completion_search.coffee +++ b/background_scripts/completion_search.coffee @@ -58,12 +58,7 @@ CompletionSearch = return callback [] if 1 == queryTerms.length and Utils.isUrl query return callback [] if Utils.hasJavascriptPrefix query - # Cache completions. However, completions depend upon both the searchUrl and the query terms. So we need - # to generate a key. We mix in some junk generated by pwgen. A key clash might be possible, but - # is vanishingly unlikely. - junk = "//Zi?ei5;o//" - completionCacheKey = searchUrl + junk + queryTerms.map((s) -> s.toLowerCase()).join junk - + completionCacheKey = JSON.stringify [ searchUrl, queryTerms ] if @completionCache.has completionCacheKey console.log "hit", completionCacheKey if @debug return callback @completionCache.get completionCacheKey -- cgit v1.2.3