mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-09-12 13:48:58 +02:00
fix: clear failed searches without racing subsequent requests
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"core.min.js": "core.6332b3c288.min.js",
|
||||
"vendor.min.js": "vendor.9de44b9059.min.js",
|
||||
"vendor.min.js": "vendor.8a52e2f74f.min.js",
|
||||
"mermaid.min.js": "mermaid.f848a72d16.min.js",
|
||||
"all.min.css": "all.99ce8f3e14.min.css"
|
||||
}
|
||||
|
||||
@@ -2614,11 +2614,13 @@ angular
|
||||
return;
|
||||
}
|
||||
$scope.fileSearchLoading = true;
|
||||
searchCanceller = $q.defer();
|
||||
const requestCanceller = $q.defer();
|
||||
searchCanceller = requestCanceller;
|
||||
$http.get(
|
||||
`/api/repo/${$scope.repoId}/files/search?q=${encodeURIComponent(query)}`,
|
||||
{ timeout: searchCanceller.promise }
|
||||
{ timeout: requestCanceller.promise }
|
||||
).then(function (res) {
|
||||
if (destroyed || searchCanceller !== requestCanceller) return;
|
||||
searchCanceller = null;
|
||||
$scope.fileSearchLoading = false;
|
||||
// Merge search results into $scope.files so the tree can render them.
|
||||
@@ -2668,8 +2670,8 @@ angular
|
||||
}
|
||||
$scope.fileSearchResults = res.data;
|
||||
}, function () {
|
||||
// Only clear loading if this wasn't a cancellation
|
||||
if (!searchCanceller) {
|
||||
if (!destroyed && searchCanceller === requestCanceller) {
|
||||
searchCanceller = null;
|
||||
$scope.fileSearchLoading = false;
|
||||
$scope.fileSearchResults = [];
|
||||
}
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -91,4 +91,11 @@ describe("frontend production regressions", function () {
|
||||
expect(h.scope.repoId).to.equal("new-repo"); expect(h.scope.files).to.have.length(0);
|
||||
expect(h.requests.at(-1).url).to.equal("/api/repo/new-repo/options");
|
||||
});
|
||||
it("finishes failed searches without letting canceled requests reset the next search", async function () {
|
||||
const h = explorer(); h.scope.fileSearchQuery = "old"; h.scope.onFileSearchChange(); const old = h.requests.at(-1);
|
||||
h.scope.fileSearchQuery = "new"; h.scope.onFileSearchChange(); const current = h.requests.at(-1);
|
||||
old.reject({ status: -1 }); await h.flush(); expect(h.scope.fileSearchLoading).to.equal(true);
|
||||
current.reject({ status: 500 }); await h.flush(); expect(h.scope.fileSearchLoading).to.equal(false);
|
||||
expect(h.scope.fileSearchResults).to.have.length(0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user