Skip to content

Commit 976b0a3

Browse files
committed
Permalink optimization: Avoid worker at initial load
If the qf parameter specifies a file name, and the leading file filter in the q parameter matches that file only, do not start search-worker.js to conserve resources, in case the user is only interested in viewing the source once.
1 parent 8cf6083 commit 976b0a3

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/crxviewer.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ function renderInitialViewFromUrlParams() {
11221122
fileFilterElem.value = q;
11231123

11241124
// Hide all files in the UI that do not match the query.
1125-
checkAndApplyFilter();
1125+
checkAndApplyFilter(true);
11261126
if (fileFilterElem.classList.contains('invalid')) {
11271127
// The query is invalid. Don't bother with searching.
11281128
return;
@@ -1144,7 +1144,14 @@ function renderInitialViewFromUrlParams() {
11441144
console.warn('No entry found with name ' + qf);
11451145
return;
11461146
}
1147-
if ([].indexOf.call(unfilteredItems, selectedItem) === -1) {
1147+
if (unfilteredItems.length === 1 && unfilteredItems[0] === selectedItem) {
1148+
// Optimization: Do not initialize the worker for TextSearchEngine when a file
1149+
// was explicitly selected and it is the only matching file.
1150+
// If the file does not match the grep pattern, then it will
1151+
// mistakenly be shown, but only initially. When the user modifies
1152+
// the search, the file will be hidden as expected, if needed.
1153+
checkAndApplyFilter.cancelDebouncedGrep();
1154+
} else if ([].indexOf.call(unfilteredItems, selectedItem) === -1) {
11481155
console.warn('The selected item is invisible because it did not match the search filter.');
11491156
}
11501157
} else if (unfilteredItems.length === 1) {
@@ -1357,6 +1364,12 @@ var checkAndApplyFilter = (function() {
13571364
grepSearch(grepTerm);
13581365
}
13591366
}
1367+
checkAndApplyFilter.cancelDebouncedGrep = function() {
1368+
if (debounceGrep) {
1369+
clearTimeout(debounceGrep);
1370+
debounceGrep = null;
1371+
}
1372+
};
13601373
(function() {
13611374
// Bind to checkbox filter
13621375
//#if CHROME || OPERA || FIREFOX

0 commit comments

Comments
 (0)