-
-
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 all 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,41 +1,62 @@ | ||
| Behaviour.specify("span.pipeline-new-node", 'NewNodeConsoleNote', 0, function(e) { | ||
| if (e.processedNewNodeConsoleNote) { | ||
| return | ||
| } | ||
| e.processedNewNodeConsoleNote = true | ||
| var label = e.getAttribute('label') | ||
| /** | ||
| * Fix label attributes | ||
| */ | ||
| function fixLabels(pipelineElement) { | ||
| var label = pipelineElement.getAttribute('label') | ||
| if (label != null) { | ||
| var html = e.innerHTML | ||
| var html = pipelineElement.innerHTML | ||
| var suffix = ' (' + label.escapeHTML() + ')'; | ||
| if (html.indexOf(suffix)<0) { | ||
| e.innerHTML = e.innerHTML.replace(/.+/, '$&' + suffix) // insert before EOL | ||
| } | ||
| } | ||
| 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; | ||
| pipelineElement.innerHTML = pipelineElement.innerHTML.replace(/.+/, '$&' + suffix) // insert before EOL | ||
| } | ||
| } | ||
| var nodes = $$('.pipeline-new-node') | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Generate hide/show links for all of the pipeline elements | ||
| */ | ||
| function addLinks (pipelineElement) { | ||
| var nodeId = pipelineElement.getAttribute('nodeId') | ||
| var startId = pipelineElement.getAttribute('startId') | ||
| if (startId == null || startId == nodeId) { | ||
| pipelineElement.innerHTML = pipelineElement.innerHTML.replace(/.+/, '$&<span class="pipeline-show-hide"> (<a href="#" onclick="showHidePipelineSection(this); return false">hide</a>)</span>') | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Generate enclosings for a element | ||
| */ | ||
| function generateEnclosing (node) { | ||
| var enclosings = new Map() | ||
| var labels = new Map() | ||
| var oid = node.getAttribute('nodeId') | ||
|
|
||
| enclosings.set(oid, node.getAttribute('enclosingId')) | ||
| labels.set(oid, node.getAttribute('label')) | ||
| } | ||
|
|
||
| /** | ||
| * Generate enclosings and labels for all of the pipeline elements | ||
| */ | ||
| function generateEnclosings () { | ||
| var enclosings = new Map() // id → enclosingId | ||
| var labels = new Map() // id → label | ||
|
Comment on lines
42
to
43
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. Did you mean to create a local version of The way things are now, it doesn't look like |
||
| var nodes = $$(".pipeline-new-node") | ||
|
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. in general, document.querySelectorAll will be much faster than $$ as one is a native browser API, and the other would be a prototypes scanner. its not a drop in replacement, but it doesn't seem like there's any prototype specific apis being used for this, so should work. |
||
|
|
||
| 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')) | ||
| appendBranchNames(oid, enclosings, labels) | ||
|
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. It looks like this is the only place where |
||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Inject the branch name in the pipeline label | ||
| */ | ||
| function appendBranchNames(nodeId, enclosings, labels) { | ||
| var id = nodeId | ||
| while (true) { | ||
| id = enclosings.get(id) | ||
|
|
@@ -51,12 +72,25 @@ Behaviour.specify("span.pipeline-new-node", 'NewNodeConsoleNote', 0, function(e) | |
| break | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Determine if the pipeline contains parallel steps | ||
| */ | ||
| function isParallelBuild(node) { | ||
| return node.innerHTML.includes('parallel') | ||
| } | ||
|
|
||
| /** | ||
| * 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 +100,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 +119,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 +144,7 @@ function showHidePipelineSection(link) { | |
| } | ||
| } | ||
| } | ||
|
|
||
| for (var i = 0; i < ids.length; i++) { | ||
| var oid = ids[i] | ||
| if (oid != id && encloses(id, oid, starts, enclosings)) { | ||
|
|
@@ -127,3 +165,22 @@ function showHidePipelineSection(link) { | |
| } | ||
| } | ||
| } | ||
|
|
||
| Behaviour.specify("span.pipeline-new-node", 'NewNodeConsoleNote', 0, function(e) { | ||
| // check if the current element has already been processed | ||
| if (e.processedNewNodeConsoleNote) { | ||
| return | ||
| } | ||
| e.processedNewNodeConsoleNote = true | ||
|
|
||
| // fix labels, generate hide/show links and generate enclosings for each element | ||
| fixLabels(e) | ||
| addLinks(e) | ||
| generateEnclosing(e); | ||
|
|
||
| // if a parallel build is underway, append branch names to the elements | ||
| // Note: we need to traverse all of the elements in parallel builds | ||
| if (isParallelBuild(e)) { | ||
| generateEnclosings() | ||
| } | ||
| }); | ||
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.