mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-09-17 16:12:15 +02:00
fix: cancel status polling when the view is destroyed
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"core.min.js": "core.6332b3c288.min.js",
|
"core.min.js": "core.6332b3c288.min.js",
|
||||||
"vendor.min.js": "vendor.914204e0bc.min.js",
|
"vendor.min.js": "vendor.57674ce30d.min.js",
|
||||||
"mermaid.min.js": "mermaid.f848a72d16.min.js",
|
"mermaid.min.js": "mermaid.f848a72d16.min.js",
|
||||||
"all.min.css": "all.99ce8f3e14.min.css"
|
"all.min.css": "all.99ce8f3e14.min.css"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1630,6 +1630,8 @@ angular
|
|||||||
$scope.rateLimitCountdown = "";
|
$scope.rateLimitCountdown = "";
|
||||||
|
|
||||||
var countdownTimer = null;
|
var countdownTimer = null;
|
||||||
|
let pollTimer = null;
|
||||||
|
let destroyed = false;
|
||||||
function startRateLimitCountdown(resetAt) {
|
function startRateLimitCountdown(resetAt) {
|
||||||
$scope.rateLimitResetAt = resetAt;
|
$scope.rateLimitResetAt = resetAt;
|
||||||
if (countdownTimer) clearInterval(countdownTimer);
|
if (countdownTimer) clearInterval(countdownTimer);
|
||||||
@@ -1653,7 +1655,9 @@ angular
|
|||||||
countdownTimer = setInterval(tick, 1000);
|
countdownTimer = setInterval(tick, 1000);
|
||||||
}
|
}
|
||||||
$scope.$on("$destroy", function () {
|
$scope.$on("$destroy", function () {
|
||||||
|
destroyed = true;
|
||||||
if (countdownTimer) clearInterval(countdownTimer);
|
if (countdownTimer) clearInterval(countdownTimer);
|
||||||
|
if (pollTimer) clearTimeout(pollTimer);
|
||||||
});
|
});
|
||||||
|
|
||||||
function parseStatusMessage(msg) {
|
function parseStatusMessage(msg) {
|
||||||
@@ -1668,6 +1672,7 @@ angular
|
|||||||
}
|
}
|
||||||
|
|
||||||
$scope.getStatus = () => {
|
$scope.getStatus = () => {
|
||||||
|
if (destroyed) return;
|
||||||
$http
|
$http
|
||||||
.get("/api/repo/" + $scope.repoId, {
|
.get("/api/repo/" + $scope.repoId, {
|
||||||
repoId: $scope.repoId,
|
repoId: $scope.repoId,
|
||||||
@@ -1675,6 +1680,7 @@ angular
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
(res) => {
|
(res) => {
|
||||||
|
if (destroyed) return;
|
||||||
$scope.repo = res.data;
|
$scope.repo = res.data;
|
||||||
if (res.data.rateLimitResetAt) {
|
if (res.data.rateLimitResetAt) {
|
||||||
startRateLimitCountdown(res.data.rateLimitResetAt);
|
startRateLimitCountdown(res.data.rateLimitResetAt);
|
||||||
@@ -1694,12 +1700,12 @@ angular
|
|||||||
} else if ($scope.repo.status == "anonymizing") {
|
} else if ($scope.repo.status == "anonymizing") {
|
||||||
$scope.progress = 75;
|
$scope.progress = 75;
|
||||||
}
|
}
|
||||||
var shouldPoll = $scope.repo.status != "ready";
|
var shouldPoll = !["ready", "removed", "expired"].includes($scope.repo.status);
|
||||||
if ($scope.repo.status == "error" && !$scope.rateLimitResetAt) {
|
if ($scope.repo.status == "error" && !$scope.rateLimitResetAt) {
|
||||||
shouldPoll = false;
|
shouldPoll = false;
|
||||||
}
|
}
|
||||||
if (shouldPoll) {
|
if (shouldPoll) {
|
||||||
setTimeout($scope.getStatus, 2000);
|
pollTimer = setTimeout($scope.getStatus, 2000);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -125,4 +125,12 @@ describe("frontend production regressions", function () {
|
|||||||
current.reject({ status: 500 }); await h.flush(); expect(h.scope.fileSearchLoading).to.equal(false);
|
current.reject({ status: 500 }); await h.flush(); expect(h.scope.fileSearchLoading).to.equal(false);
|
||||||
expect(h.scope.fileSearchResults).to.have.length(0);
|
expect(h.scope.fileSearchResults).to.have.length(0);
|
||||||
});
|
});
|
||||||
|
it("cancels status polling on destroy, including late responses", async function () {
|
||||||
|
const h = harness(); h.defs.statusController.at(-1)(h.scope, h.http, { repoId: "repo" });
|
||||||
|
h.requests[0].resolve({ data: { status: "preparing" } }); await h.flush();
|
||||||
|
expect(h.timers.size).to.equal(1); const callback = [...h.timers.values()][0];
|
||||||
|
h.emit("$destroy"); expect(h.timers.size).to.equal(0); callback(); expect(h.requests).to.have.length(1);
|
||||||
|
const late = harness(); late.defs.statusController.at(-1)(late.scope, late.http, { repoId: "repo" });
|
||||||
|
late.emit("$destroy"); late.requests[0].resolve({ data: { status: "preparing" } }); await late.flush(); expect(late.timers.size).to.equal(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user