-
-
Notifications
You must be signed in to change notification settings - Fork 140
Fix issue with big logs, causing the browser to freeze (JENKINS-56377) #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
f84c16b
f785961
10a58b7
26cc512
b0c2eb2
d6f12dd
1cd870c
43c58ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,62 +1,78 @@ | ||
| Behaviour.specify("span.pipeline-new-node", 'NewNodeConsoleNote', 0, function(e) { | ||
| if (e.processedNewNodeConsoleNote) { | ||
| return | ||
| } | ||
| e.processedNewNodeConsoleNote = true | ||
| var label = e.getAttribute('label') | ||
| if (label != null) { | ||
| var html = e.innerHTML | ||
| var suffix = ' (' + label.escapeHTML() + ')'; | ||
| if (html.indexOf(suffix)<0) { | ||
| e.innerHTML = e.innerHTML.replace(/.+/, '$&' + suffix) // insert before EOL | ||
| Behaviour.specify("span.pipeline-new-node", 'NewNodeConsoleNote', 0, function (e) { | ||
| /** | ||
| * The setTimeout() method calls a function or evaluates an expression after a specified number of milliseconds. | ||
| * It is used here to prevent a browser freeze that might occur if a very big log is being evaluated. | ||
| */ | ||
| setTimeout(() => { | ||
| var nodeId = e.getAttribute('nodeId') | ||
| var oid = e.getAttribute('nodeId') | ||
| var startId = e.getAttribute('startId') | ||
| var label = e.getAttribute('label') | ||
| var nodes = $$('.pipeline-new-node') | ||
| var enclosings = new Map() // id → enclosingId | ||
| var labels = new Map() // id → label | ||
|
|
||
| if (e.processedNewNodeConsoleNote) { | ||
| return | ||
| } | ||
| } | ||
| var nodeId = e.getAttribute('nodeId') | ||
| var startId = e.getAttribute('startId') | ||
| if (startId == null || startId == nodeId) { | ||
| e.innerHTML = e.innerHTML.replace(/.+/, '$&<span class="pipeline-show-hide"> (<a href="#" onclick="showHidePipelineSection(this); return false">hide</a>)</span>') | ||
| // TODO automatically hide second and subsequent branches: namely, in case a node has the same parent as an earlier one | ||
| } | ||
| // The CSS rule for branch names only needs to be added once per node, so we | ||
| // check in case we are viewing the truncated log and have already processed | ||
| // a duplicate synthetic span element for this node. | ||
| var maybeDupeNodes = $$('[nodeid=\"'+nodeId+'\"].pipeline-new-node'); | ||
| for (var i = 0; i < maybeDupeNodes.length; i++) { | ||
| var node = maybeDupeNodes[i]; | ||
| if (node !== e && node.processedNewNodeConsoleNote) { | ||
| return; | ||
| e.processedNewNodeConsoleNote = true | ||
|
|
||
| if (label != null) { | ||
| var html = e.innerHTML | ||
| var suffix = ' (' + label.escapeHTML() + ')'; | ||
| if (html.indexOf(suffix) < 0) { | ||
| e.innerHTML = e.innerHTML.replace(/.+/, '$&' + suffix) // insert before EOL | ||
| } | ||
| } | ||
| } | ||
| var nodes = $$('.pipeline-new-node') | ||
| var enclosings = new Map() // id → enclosingId | ||
| var labels = new Map() // id → label | ||
| for (var i = 0; i < nodes.length; i++) { | ||
| var node = nodes[i] | ||
| var oid = node.getAttribute('nodeId') | ||
| enclosings.set(oid, node.getAttribute('enclosingId')) | ||
| labels.set(oid, node.getAttribute('label')) | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this loop causes branch names to no longer be shown when log output changes from one branch to another in many cases. The problem is that in the The old code is not optimal because we create a fresh Here is a Pipeline you can run to compare the behavior with and without this PR to see what I mean:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. I will try to find a solution to this problem. |
||
| var id = nodeId | ||
| while (true) { | ||
| id = enclosings.get(id) | ||
| if (id == null) { | ||
| break | ||
|
|
||
| // generate hide/show hyperlinks | ||
| if (startId == null || startId == nodeId) { | ||
| e.innerHTML = e.innerHTML.replace(/.+/, '$&<span class="pipeline-show-hide"> (<a href="#" onclick="showHidePipelineSection(this); return false">hide</a>)</span>') | ||
| } | ||
| var label = labels.get(id) | ||
| if (label != null && label.indexOf('Branch: ') == 0) { | ||
| var branch = label.substring(8) | ||
| var ss = document.styleSheets[0] | ||
| // TODO https://stackoverflow.com/a/18990994/12916 does not scale well to add width: 25em; text-align: right | ||
| ss.insertRule('.pipeline-node-' + nodeId + '::before {content: "[' + branch.escapeHTML() + '] "; color: #9A9999; position: absolute; transform: translateX(-100%)}', ss.cssRules == null ? 0 : ss.cssRules.length) | ||
| break | ||
|
|
||
| // The CSS rule for branch names only needs to be added once per node, so we | ||
|
||
| // check in case we are viewing the truncated log and have already processed | ||
| // a duplicate synthetic span element for this node. | ||
| var maybeDupeNodes = $$('[nodeid=\"' + nodeId + '\"].pipeline-new-node'); | ||
| for (var i = 0; i < maybeDupeNodes.length; i++) { | ||
| var node = maybeDupeNodes[i]; | ||
| if (node !== e && node.processedNewNodeConsoleNote) { | ||
| return; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| enclosings.set(oid, e.getAttribute('enclosingId')) | ||
| labels.set(oid, e.getAttribute('label')) | ||
|
|
||
| var id = nodeId | ||
| while (true) { | ||
| id = enclosings.get(id) | ||
| if (id == null) { | ||
| break | ||
| } | ||
| var label = labels.get(id) | ||
| if (label != null && label.indexOf('Branch: ') == 0) { | ||
| var branch = label.substring(8) | ||
| var ss = document.styleSheets[0] | ||
| // TODO https://stackoverflow.com/a/18990994/12916 does not scale well to add width: 25em; text-align: right | ||
| ss.insertRule('.pipeline-node-' + nodeId + '::before {content: "[' + branch.escapeHTML() + '] "; color: #9A9999; position: absolute; transform: translateX(-100%)}', ss.cssRules == null ? 0 : ss.cssRules.length) | ||
| break | ||
| } | ||
| } | ||
| }, 5000) | ||
|
||
| }); | ||
|
|
||
|
|
||
| /** | ||
| * Functionality to show/hide a pipeline step (label) | ||
| * | ||
| * @param link - hyperlink element | ||
| **/ | ||
| function showHidePipelineSection(link) { | ||
| var span = link.parentNode.parentNode | ||
| var id = span.getAttribute('nodeId') | ||
| var display | ||
|
|
||
| if (link.textContent === 'hide') { | ||
| display = 'none' | ||
| link.textContent = 'show' | ||
|
|
@@ -66,7 +82,8 @@ function showHidePipelineSection(link) { | |
| link.textContent = 'hide' | ||
| link.parentNode.className = 'pipeline-show-hide' | ||
| } | ||
| var showHide = function(id, display) { | ||
|
|
||
| var showHide = function (id, display) { | ||
| var sect = '.pipeline-node-' + id | ||
| var ss = document.styleSheets[0] | ||
| for (var i = 0; i < ss.cssRules.length; i++) { | ||
|
|
@@ -84,14 +101,16 @@ function showHidePipelineSection(link) { | |
| var ids = [] | ||
| var starts = new Map() | ||
| var enclosings = new Map() // id → enclosingId | ||
|
|
||
| for (var i = 0; i < nodes.length; i++) { | ||
| var node = nodes[i] | ||
| var oid = node.getAttribute('nodeId') | ||
| ids.push(oid) | ||
| starts.set(oid, node.getAttribute('startId')) | ||
| enclosings.set(oid, node.getAttribute('enclosingId')) | ||
| } | ||
| var encloses = function(enclosing, enclosed, starts, enclosings) { | ||
|
|
||
| var encloses = function (enclosing, enclosed, starts, enclosings) { | ||
| var id = enclosed | ||
| var start = starts.get(id) | ||
| if (start != null && start != id) { | ||
|
|
@@ -107,6 +126,7 @@ function showHidePipelineSection(link) { | |
| } | ||
| } | ||
| } | ||
|
|
||
| for (var i = 0; i < ids.length; i++) { | ||
| var oid = ids[i] | ||
| if (oid != id && encloses(id, oid, starts, enclosings)) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is already filed in JIRA somewhere.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this part, because it would probably make more sense to generate this inside the back-end.
EDIT: upon further inspection, I will leave it as it was before due to its performance impact being way smaller than I thought (almost not noticeable).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have clarified that my review comment was in reference to the removal of the one-line code comment, which is properly an RFE that should be tracked in Jira, not to behavioral changes in your patch.