Skip to content

Commit

Permalink
Omnibox add no cached query API
Browse files Browse the repository at this point in the history
  • Loading branch information
Folyd committed Apr 15, 2020
1 parent 1243470 commit 78f9d10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions extension/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,6 @@ omnibox.addPrefixQueryEvent(":", {
},
});

omnibox.addNoCacheQueries("@", ":");

window.crateSearcher = crateSearcher;
12 changes: 10 additions & 2 deletions extension/omnibox.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ function Omnibox(defaultSuggestion, maxSuggestionSize = 8) {
// Cache the last query and result to speed up the page down.
this.cachedQuery = null;
this.cachedResult = null;
// A set of query which should not be cached.
this.noCacheQueries = new Set();
}

Omnibox.prototype.setDefaultSuggestion = function(description, content) {
Expand Down Expand Up @@ -58,8 +60,10 @@ Omnibox.prototype.bootstrap = function({onSearch, onFormat, onAppend, onSelected
results = this.cachedResult;
} else {
results = this.performSearch(query);
this.cachedQuery = query;
this.cachedResult = results;
if (!this.noCacheQueries.has(query)) {
this.cachedQuery = query;
this.cachedResult = results;
}
}

let totalPage = Math.ceil(results.length / this.maxSuggestionSize);
Expand Down Expand Up @@ -151,6 +155,10 @@ Omnibox.prototype.navigateToUrl = function(url, disposition) {
}
};

Omnibox.prototype.addNoCacheQueries = function(...queries) {
queries.forEach(query => this.noCacheQueries.add(query));
};

class QueryEvent {
constructor({
onSearch, onFormat, onAppend,
Expand Down

0 comments on commit 78f9d10

Please sign in to comment.