mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 12:42:26 +01:00
Cache keyword-search filter
This commit is contained in:
@@ -316,7 +316,7 @@ liberator.Bookmarks = function () //{{{
|
|||||||
{
|
{
|
||||||
if (bypassCache) // Is this really necessary anymore?
|
if (bypassCache) // Is this really necessary anymore?
|
||||||
cache.load();
|
cache.load();
|
||||||
return liberator.completion.cached(cache.bookmarks, filter, function () cache.bookmarks,
|
return liberator.completion.cached("bookmarks", filter, function () cache.bookmarks,
|
||||||
"filterURLArray", tags);
|
"filterURLArray", tags);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -543,10 +543,14 @@ liberator.Completion = function () //{{{
|
|||||||
|
|
||||||
cached: function (key, filter, generate, method)
|
cached: function (key, filter, generate, method)
|
||||||
{
|
{
|
||||||
if (!filter || filter.indexOf(cacheFilter[key]) != 0)
|
if (!filter && cacheFilter[key] || filter.indexOf(cacheFilter[key]) != 0)
|
||||||
cacheResults[key] = generate(filter);
|
cacheResults[key] = generate(filter);
|
||||||
|
if (key == "searches")
|
||||||
|
liberator.dump({keyword: key, cacheFilter: cacheFilter[key], filter: filter, searches: {toString: function() json.encode(cacheResults[key])}});
|
||||||
cacheFilter[key] = filter;
|
cacheFilter[key] = filter;
|
||||||
|
if (cacheResults[key].length)
|
||||||
return cacheResults[key] = this[method].apply(this, [cacheResults[key], filter].concat(Array.splice(arguments, 4)));
|
return cacheResults[key] = this[method].apply(this, [cacheResults[key], filter].concat(Array.splice(arguments, 4)));
|
||||||
|
return [];
|
||||||
},
|
},
|
||||||
|
|
||||||
// discard all entries in the 'urls' array, which don't match 'filter
|
// discard all entries in the 'urls' array, which don't match 'filter
|
||||||
@@ -728,6 +732,13 @@ liberator.Completion = function () //{{{
|
|||||||
ex: function (str)
|
ex: function (str)
|
||||||
{
|
{
|
||||||
substrings = [];
|
substrings = [];
|
||||||
|
if (str.indexOf(cacheFilter["ex"]) != 0)
|
||||||
|
{
|
||||||
|
cacheFilter = {};
|
||||||
|
cacheResults = {};
|
||||||
|
}
|
||||||
|
cacheFilter["ex"] = str;
|
||||||
|
|
||||||
var [count, cmd, special, args] = liberator.commands.parseCommand(str);
|
var [count, cmd, special, args] = liberator.commands.parseCommand(str);
|
||||||
var completions = [];
|
var completions = [];
|
||||||
var start = 0;
|
var start = 0;
|
||||||
@@ -841,6 +852,7 @@ liberator.Completion = function () //{{{
|
|||||||
let keywords = liberator.bookmarks.getKeywords().map(function (k) [k[0], k[1], k[3], k[2]]);
|
let keywords = liberator.bookmarks.getKeywords().map(function (k) [k[0], k[1], k[3], k[2]]);
|
||||||
let engines = this.filter(keywords.concat(liberator.bookmarks.getSearchEngines()), filter, false, true);
|
let engines = this.filter(keywords.concat(liberator.bookmarks.getSearchEngines()), filter, false, true);
|
||||||
|
|
||||||
|
let generate = function () {
|
||||||
let history = liberator.history.get();
|
let history = liberator.history.get();
|
||||||
let searches = [];
|
let searches = [];
|
||||||
for (let [, k] in Iterator(keywords))
|
for (let [, k] in Iterator(keywords))
|
||||||
@@ -859,11 +871,10 @@ liberator.Completion = function () //{{{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (searches.length)
|
return searches;
|
||||||
{
|
|
||||||
searches = this.filter(searches, args, false, true);
|
|
||||||
searches.forEach(function (a) a[0] = keyword + " " + a[0]);
|
|
||||||
}
|
}
|
||||||
|
let searches = this.cached("searches-" + keyword, args, generate, "filter", [false, true]);
|
||||||
|
searches = searches.map(function (a) (a = a.concat(), a[0] = keyword + " " + a[0], a));
|
||||||
return [0, searches.concat(engines)];
|
return [0, searches.concat(engines)];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user