diff options
| author | Stephen Blott | 2015-06-07 05:36:28 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2015-06-07 05:56:02 +0100 | 
| commit | 4aef35e1b98883d176e9677764b3c50327674214 (patch) | |
| tree | a0864c3fc8a883a3e835642140890ed37476c600 /background_scripts/completion.coffee | |
| parent | 616261ef8364cbd99765d651dfe8acd5ff55b453 (diff) | |
| download | vimium-4aef35e1b98883d176e9677764b3c50327674214.tar.bz2 | |
Speed up vomnibar load.
With #1697, the vomnibar used with a custom-search keyword is not
initially empty (it shows the primary suggestion for the custom search
engine, even if the query is empty).  The way things were structured
previously, the user nevertheless had to wait until the history cache
(which was not actually required) had been fetched before the vomnibar
was updated.
This commit just flips things around a bit such that,
   - onComplete() is called immediately if the history is not actually
     required, and
   - the history cache is primed before it is needed, so it will
     (hopefully) be available before the user's next keystroke.
This avoids a noticable delay, particularly on start up and with a large
history.
(This is part of a sequence of vomnibar UX tweaks.)
Diffstat (limited to 'background_scripts/completion.coffee')
| -rw-r--r-- | background_scripts/completion.coffee | 39 | 
1 files changed, 20 insertions, 19 deletions
| diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 189929b4..fb5a6120 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -252,25 +252,26 @@ class BookmarkCompleter  class HistoryCompleter    filter: ({ queryTerms, seenTabToOpenCompletionList }, onComplete) -> -    @currentSearch = { queryTerms: @queryTerms, onComplete: @onComplete } -    results = [] -    HistoryCache.use (history) => -      results = -        if queryTerms.length > 0 -          history.filter (entry) -> RankingUtils.matches(queryTerms, entry.url, entry.title) -        else if seenTabToOpenCompletionList -          # <Tab> opens the completion list, even without a query. -          history -        else -          [] -      onComplete results.map (entry) => -        new Suggestion -          queryTerms: queryTerms -          type: "history" -          url: entry.url -          title: entry.title -          relevancyFunction: @computeRelevancy -          relevancyData: entry +    if queryTerms.length == 0 and not seenTabToOpenCompletionList +      onComplete [] +      # Prime the history cache so that it will (hopefully) be available on the user's next keystroke. +      Utils.nextTick -> HistoryCache.use -> +    else +      HistoryCache.use (history) => +        results = +          if 0 < queryTerms.length +            history.filter (entry) -> RankingUtils.matches queryTerms, entry.url, entry.title +          else +            # The user has typed <Tab> to open the entire history (sorted by recency). +            history +        onComplete results.map (entry) => +          new Suggestion +            queryTerms: queryTerms +            type: "history" +            url: entry.url +            title: entry.title +            relevancyFunction: @computeRelevancy +            relevancyData: entry    computeRelevancy: (suggestion) ->      historyEntry = suggestion.relevancyData | 
