Skip to content

Commit 2fcdadd

Browse files
author
Jenkins Contributor
committed
[JENKINS-76278] Avoid repeated getData() calls in Manage Old Data page
1 parent 396f78b commit 2fcdadd

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

core/src/main/resources/hudson/diagnosis/OldDataMonitor/manage.jelly

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ THE SOFTWARE.
2727
<l:settings-subpage managementLink="${it.managementLink}">
2828
<p class="jenkins-!-margin-top-0">${%blurb.1}</p>
2929
<p>${%blurb.2}</p>
30-
30+
31+
<j:set var="allData" value="${it.data}"/>
32+
<j:set var="totalCount" value="${allData.size()}"/>
33+
<j:set var="maxDisplay" value="${1000}"/>
34+
3135
<!-- First set a flag to check if we'll have any valid data -->
3236
<j:set var="hasValidData" value="false"/>
3337
<j:set var="hasExtra" value="false"/>
34-
<j:forEach var="item" items="${it.data.entrySet()}">
38+
<j:forEach var="item" items="${allData.entrySet()}">
3539
<j:if test="${item.value!=''}">
3640
<j:set var="hasValidData" value="true"/>
3741
</j:if>
@@ -45,6 +49,11 @@ THE SOFTWARE.
4549
<l:notice title="${%No old data}" icon="symbol-trash-bin"/>
4650
</j:when>
4751
<j:otherwise>
52+
<j:if test="${totalCount > maxDisplay}">
53+
<div class="jenkins-!-warning-color">
54+
${%tooManyEntries(maxDisplay, totalCount)}
55+
</div>
56+
</j:if>
4857
<j:if test="${hasValidData}">
4958
<table class="jenkins-table sortable">
5059
<thead>
@@ -56,8 +65,9 @@ THE SOFTWARE.
5665
</tr>
5766
</thead>
5867
<tbody>
59-
<j:forEach var="item" items="${it.data.entrySet()}">
60-
<j:if test="${item.value!=''}">
68+
<j:set var="count" value="${0}"/>
69+
<j:forEach var="item" items="${allData.entrySet()}">
70+
<j:if test="${item.value!='' and count &lt; maxDisplay}">
6171
<j:set var="obj" value="${item.key}"/>
6272
<tr>
6373
<td>${obj.class.name}</td>
@@ -74,6 +84,7 @@ THE SOFTWARE.
7484
</td>
7585
<td style="white-space:normal">${item.value.extra}</td>
7686
</tr>
87+
<j:set var="count" value="${count + 1}"/>
7788
</j:if>
7889
</j:forEach>
7990
</tbody>
@@ -112,14 +123,16 @@ THE SOFTWARE.
112123
</tr>
113124
</thead>
114125
<tbody>
115-
<j:forEach var="item" items="${it.data.entrySet()}">
116-
<j:if test="${item.value.extra!=null and item.value==''}">
126+
<j:set var="count" value="${0}"/>
127+
<j:forEach var="item" items="${allData.entrySet()}">
128+
<j:if test="${item.value.extra!=null and item.value=='' and count &lt; maxDisplay}">
117129
<j:set var="obj" value="${item.key}"/>
118130
<tr>
119131
<td>${obj.class.name}</td>
120132
<td>${obj.fullName?:obj.fullDisplayName?:obj.displayName?:obj.name}</td>
121133
<td style="white-space:normal">${item.value.extra}</td>
122134
</tr>
135+
<j:set var="count" value="${count + 1}"/>
123136
</j:if>
124137
</j:forEach>
125138
</tbody>

core/src/main/resources/hudson/diagnosis/OldDataMonitor/manage.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ blurb.6=\
5050
It is ok to leave unreadable data in these items/records, as Jenkins will simply ignore it. \
5151
To avoid the log messages at Jenkins startup you can permanently delete the unreadable data \
5252
by resaving these items/records using the button below the list.
53+
tooManyEntries=\
54+
Showing first {0} of {1} entries. Use the upgrade or discard buttons to reduce the count.

test/src/test/java/hudson/diagnosis/OldDataMonitorTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package hudson.diagnosis;
2626

2727
import static org.junit.jupiter.api.Assertions.assertEquals;
28+
import static org.junit.jupiter.api.Assertions.assertFalse;
2829
import static org.junit.jupiter.api.Assertions.assertNotNull;
2930

3031
import hudson.XmlFile;
@@ -156,6 +157,20 @@ void unlocatableRun() throws Exception {
156157

157158
}
158159

160+
@Issue("JENKINS-76278")
161+
@Test
162+
void managePageRendering() throws Exception {
163+
FreeStyleProject p = r.createFreeStyleProject("testProject");
164+
FreeStyleBuild b = r.buildAndAssertSuccess(p);
165+
OldDataMonitor.report(b, "1.0");
166+
167+
OldDataMonitor odm = OldDataMonitor.get(r.jenkins);
168+
assertFalse(odm.getData().isEmpty());
169+
170+
// verify the manage page loads without error
171+
r.createWebClient().goTo("administrativeMonitor/OldData/manage");
172+
}
173+
159174
public static final class BadAction extends InvisibleAction {
160175
private Object writeReplace() {
161176
throw new IllegalStateException("broken");

0 commit comments

Comments
 (0)