1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 16:32:27 +01:00

Cache keyword-search filter

This commit is contained in:
Kris Maglione
2008-10-08 16:05:19 +00:00
parent 9d54b4f6cf
commit 97d1c1afd9
2 changed files with 32 additions and 21 deletions

View File

@@ -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);
}, },

View File

@@ -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;
return cacheResults[key] = this[method].apply(this, [cacheResults[key], filter].concat(Array.splice(arguments, 4))); if (cacheResults[key].length)
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,29 +852,29 @@ 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 history = liberator.history.get(); let generate = function () {
let searches = []; let history = liberator.history.get();
for (let [, k] in Iterator(keywords)) let searches = [];
{ for (let [, k] in Iterator(keywords))
if (k[0].toLowerCase() != keyword.toLowerCase() || k[3].indexOf("%s") == -1)
continue;
let [begin, end] = k[3].split("%s");
for (let [, h] in Iterator(history))
{ {
if (h[0].indexOf(begin) == 0 && (!end.length || h[0].substr(-end.length) == end)) if (k[0].toLowerCase() != keyword.toLowerCase() || k[3].indexOf("%s") == -1)
continue;
let [begin, end] = k[3].split("%s");
for (let [, h] in Iterator(history))
{ {
let query = h[0].substr(begin.length, h[0].length - end.length); if (h[0].indexOf(begin) == 0 && (!end.length || h[0].substr(-end.length) == end))
searches.push([decodeURIComponent(query), {
<>{begin}<span class="hl-Filter">{query}</span>{end}</>, let query = h[0].substr(begin.length, h[0].length - end.length);
k[2]]); searches.push([decodeURIComponent(query),
<>{begin}<span class="hl-Filter">{query}</span>{end}</>,
k[2]]);
}
} }
} }
return searches;
} }
if (searches.length) 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));
searches = this.filter(searches, args, false, true);
searches.forEach(function (a) a[0] = keyword + " " + a[0]);
}
return [0, searches.concat(engines)]; return [0, searches.concat(engines)];
}, },