Skip to content

Commit 5c98135

Browse files
committed
Auto merge of #6483 - xFrednet:5386-github-ticket-search, r=killercup
Website issue tracker link and better search performance This PR implements some improvements to the website: 1. Added a "Search on Github" link to the "Known problems" section (Closes #5386) ![example_3](https://user-images.githubusercontent.com/17087237/102718215-e9f12500-42de-11eb-8c1b-487f8184aaf7.png) <details> <summary>Another mock up I created with the GitHub logo</summary> ![example_2](https://user-images.githubusercontent.com/17087237/102718281-3472a180-42df-11eb-99b8-7f6d76da2b55.png) </details> 2. Only starting the search after three letters and improving the search performance in general. (Followup #6477) ### Testing These changes can be tested locally by: 1. Clone this branch 2. Download the current lint index from the [gh-pages branch](https://github.com/rust-lang/rust-clippy/blob/gh-pages/master/lints.json) 3. Put it next to the `util/gh-pages/index.html` and open the html file. Make sure that it can load the lint data. (Browsers can be a bit iffy when opening a local html page and loading data) ### Sources for search performance: 1. [A stackoverflow about angular filter performance](https://stackoverflow.com/questions/26876514/optimize-angular-filter-performance) * I selected a search debounce of 50ms that's fast enough to catch fast deletion and typing but responsive enough to not bother the user 2. [A stackoverflow about string comparison speeds](https://stackoverflow.com/questions/5296268/fastest-way-to-check-a-string-contain-another-substring-in-javascript) 3. [JS benchmarks for string search performance (`indexOf` seams to be the best)](https://jsben.ch/9cwLJ) Note: The performance is still a bit poor when going from a specific lint to no search filter. I suspect that angular is recreating all lint items when the filter is cleared causing a major lag spike. The filter functions is at least optimized for little to no search. --- changelog: Added a "Search on GitHub" link to the website
2 parents 971e5b3 + f055e7f commit 5c98135

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

util/gh-pages/index.html

+31-23
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ <h1>ALL the Clippy Lints</h1>
7777
<div class="col-md-12 form-horizontal">
7878
<div class="input-group">
7979
<label class="input-group-addon" id="filter-label" for="filter-input">Filter:</label>
80-
<input type="text" class="form-control" placeholder="Keywords or search string" id="filter-input" ng-model="search" />
80+
<input type="text" class="form-control" placeholder="Keywords or search string" id="filter-input" ng-model="search" ng-model-options="{debounce: 50}"/>
8181
<span class="input-group-btn">
8282
<button class="btn btn-default" type="button" ng-click="search = ''">
8383
Clear
@@ -119,6 +119,7 @@ <h4 class="list-group-item-heading">
119119
{{title}}
120120
</h4>
121121
<div class="list-group-item-text" ng-bind-html="text | markdown"></div>
122+
<a ng-if="title == 'Known problems'" href="https://github.com/rust-lang/rust-clippy/issues?q=is%3Aissue+is%3Aopen+{{lint.id}}">Search on GitHub</a>
122123
</li>
123124
</ul>
124125
</article>
@@ -180,6 +181,22 @@ <h4 class="list-group-item-heading">
180181
}
181182
}
182183

184+
function searchLint(lint, term) {
185+
for (const field in lint.docs) {
186+
// Continue if it's not a property
187+
if (!lint.docs.hasOwnProperty(field)) {
188+
continue;
189+
}
190+
191+
// Return if not found
192+
if (lint.docs[field].toLowerCase().indexOf(term) !== -1) {
193+
return true;
194+
}
195+
}
196+
197+
return false;
198+
}
199+
183200
angular.module("clippy", [])
184201
.filter('markdown', function ($sce) {
185202
return function (text) {
@@ -216,40 +233,31 @@ <h4 class="list-group-item-heading">
216233
};
217234

218235
$scope.bySearch = function (lint, index, array) {
219-
let search_str = $scope.search;
236+
let searchStr = $scope.search;
220237
// It can be `null` I haven't missed this value
221-
if (search_str == null || search_str.length == 0) {
238+
if (searchStr == null || searchStr.length < 3) {
222239
return true;
223240
}
224-
search_str = search_str.toLowerCase();
241+
searchStr = searchStr.toLowerCase();
225242

226243
// Search by id
227-
let id_search = search_str.trim().replace(/(\-| )/g, "_");
228-
if (lint.id.includes(id_search)) {
244+
if (lint.id.indexOf(searchStr.replace("-", "_")) !== -1) {
229245
return true;
230246
}
231247

232248
// Search the description
233249
// The use of `for`-loops instead of `foreach` enables us to return early
234-
let search_lint = (lint, therm) => {
235-
for (const field in lint.docs) {
236-
// Continue if it's not a property
237-
if (!lint.docs.hasOwnProperty(field)) {
238-
continue;
239-
}
240-
241-
// Return if not found
242-
if (lint.docs[field].toLowerCase().includes(therm)) {
243-
return true;
244-
}
250+
let terms = searchStr.split(" ");
251+
for (index = 0; index < terms.length; index++) {
252+
if (lint.id.indexOf(terms[index]) !== -1) {
253+
continue;
245254
}
246-
return false;
247-
};
248-
let therms = search_str.split(" ");
249-
for (index = 0; index < therms.length; index++) {
250-
if (!search_lint(lint, therms[index])) {
251-
return false;
255+
256+
if (searchLint(lint, terms[index])) {
257+
continue;
252258
}
259+
260+
return false;
253261
}
254262

255263
return true;

0 commit comments

Comments
 (0)