提交 2f0632ae 编写于 作者: L lpancescu 提交者: Oliver Gondža

[JENKINS-10912] Use setInterval in refreshPart (#2539)

* [JENKINS-10912] Use setInterval in refreshPart

The current implementation of refreshPart creates a new closure every 5
seconds, which, in combination with XMLHttpRequest objects, results in a
significant memory leak in all major browsers. By using
window.setInterval to schedule periodic refreshes, only one closure per
id is created. Please see issue #10912 in the Jenkins tracker for
further details.

* Stop periodical calls if we can't find the div

* Don't check if isRunAsTest changed after page load

(cherry picked from commit 096614a6)
上级 1875144a
...@@ -1486,6 +1486,7 @@ function expandTextArea(button,id) { ...@@ -1486,6 +1486,7 @@ function expandTextArea(button,id) {
// refresh a part of the HTML specified by the given ID, // refresh a part of the HTML specified by the given ID,
// by using the contents fetched from the given URL. // by using the contents fetched from the given URL.
function refreshPart(id,url) { function refreshPart(id,url) {
var intervalID = null;
var f = function() { var f = function() {
if(isPageVisible()) { if(isPageVisible()) {
new Ajax.Request(url, { new Ajax.Request(url, {
...@@ -1493,6 +1494,8 @@ function refreshPart(id,url) { ...@@ -1493,6 +1494,8 @@ function refreshPart(id,url) {
var hist = $(id); var hist = $(id);
if (hist == null) { if (hist == null) {
console.log("There's no element that has ID of " + id); console.log("There's no element that has ID of " + id);
if (intervalID !== null)
window.clearInterval(intervalID);
return; return;
} }
var p = hist.up(); var p = hist.up();
...@@ -1505,22 +1508,14 @@ function refreshPart(id,url) { ...@@ -1505,22 +1508,14 @@ function refreshPart(id,url) {
Behaviour.applySubtree(node); Behaviour.applySubtree(node);
layoutUpdateCallback.call(); layoutUpdateCallback.call();
if(isRunAsTest) return;
refreshPart(id,url);
} }
}); });
} else {
// Reschedule
if(isRunAsTest) return;
refreshPart(id,url);
} }
}; };
// if run as test, just do it once and do it now to make sure it's working, // if run as test, just do it once and do it now to make sure it's working,
// but don't repeat. // but don't repeat.
if(isRunAsTest) f(); if(isRunAsTest) f();
else window.setTimeout(f, 5000); else intervalID = window.setInterval(f, 5000);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册