diff options
| author | Niklas Baumstark | 2012-01-23 22:29:13 +0100 |
|---|---|---|
| committer | Niklas Baumstark | 2012-04-10 23:54:38 +0200 |
| commit | 6bc1d44939c9b4557ef8648a6e645e73caaa0623 (patch) | |
| tree | a9521176835e10d8c393b10b6f86386ec3554aec | |
| parent | 958dd003ea7f3aaefc7c785bbb353b1c26641bc1 (diff) | |
| download | vimium-6bc1d44939c9b4557ef8648a6e645e73caaa0623.tar.bz2 | |
improve perfmance by caching history results in the background page.
Also decrease the number of included results slightly.
| -rw-r--r-- | background_page.html | 33 | ||||
| -rw-r--r-- | fuzzyMode.js | 2 |
2 files changed, 31 insertions, 4 deletions
diff --git a/background_page.html b/background_page.html index 641fea1f..99c7d430 100644 --- a/background_page.html +++ b/background_page.html @@ -75,6 +75,8 @@ if (portHandlers[port.name]) port.onMessage.addListener(portHandlers[port.name]); + // prefetch history + useHistory(function() {}); }); chrome.extension.onRequest.addListener(function (request, sender, sendResponse) { @@ -306,13 +308,38 @@ }); }; - function getHistory(args, port) { + var cachedHistory = null; + function useHistory(callback) { + if (cachedHistory !== null) { + callback(cachedHistory); + return; + } + chrome.history.search({ text: '', - maxResults: args.maxResults || 1000, + maxResults: 20000, startTime: 0, }, function(history) { - port.postMessage({history:history}); + // sorting in asceding order, so we can push new items to the end later + history.sort(function(a, b) { + // visitCount may be undefined + return (a.visitCount || 0) - (b.visitCount || 0); + }); + cachedHistory = history; + callback(cachedHistory); + }); + } + + chrome.history.onVisited.addListener(function(item) { + if (cachedHistory === null) return; + cachedHistory.push(item); + }); + + function getHistory(args, port) { + useHistory(function(history) { + port.postMessage({ + history: history.slice(history.length - args.maxResults) + }); }); }; diff --git a/fuzzyMode.js b/fuzzyMode.js index a91fab37..a98e3f21 100644 --- a/fuzzyMode.js +++ b/fuzzyMode.js @@ -12,7 +12,7 @@ var fuzzyMode = (function() { '?' : [ 'search', function(query) { return utils.createSearchUrl(query) } ], }); else if (name === 'history') - return new completion.FuzzyHistoryCompleter(2000); + return new completion.FuzzyHistoryCompleter(1500); else if (name === 'bookmarks') return new completion.FuzzyBookmarkCompleter(); else if (name === 'tabs') |
