Skip to content

Commit 9037052

Browse files
author
Dmytro Ukhlov
committed
Add ability to limit RunListProgressiveRendering records to return
1 parent 6998f5f commit 9037052

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

core/src/main/java/jenkins/widgets/RunListProgressiveRendering.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
import hudson.model.Run;
2828
import hudson.util.RunList;
2929
import java.util.ArrayList;
30+
import java.util.Iterator;
3031
import java.util.List;
3132
import jenkins.util.ProgressiveRendering;
33+
import jenkins.util.SystemProperties;
3234
import net.sf.json.JSON;
3335
import net.sf.json.JSONArray;
3436
import net.sf.json.JSONObject;
@@ -43,10 +45,11 @@ public abstract class RunListProgressiveRendering extends ProgressiveRendering {
4345

4446
/**
4547
* Since we cannot predict how many runs there will be, just show an ever-growing progress bar.
46-
* The first increment will be sized as if this many runs will be in the total,
48+
* The first increments will be sized so that 50% progress is reached when half of this many runs have been processed.
4749
* but then like Zeno’s paradox we will never seem to finish until we actually do.
4850
*/
49-
private static final double MAX_LIKELY_RUNS = 20; // if (MAX_LIKELY_RUNS / 2) runs are processed, progress is 0.5
51+
private static final double MAX_LIKELY_RUNS = 20;
52+
private static final int LIMIT = SystemProperties.getInteger(RunListProgressiveRendering.class.getName() + ".limit", Integer.MAX_VALUE);
5053
private final List<JSONObject> results = new ArrayList<>();
5154
private Iterable<? extends Run<?, ?>> builds;
5255

@@ -57,10 +60,9 @@ public void setBuilds(Iterable<? extends Run<?, ?>> builds) {
5760

5861
@Override protected void compute() throws Exception {
5962
int processed = 0;
60-
for (Run<?, ?> build : builds) {
61-
if (canceled()) {
62-
return;
63-
}
63+
Iterator<? extends Run<?, ?>> iter = builds.iterator();
64+
while (iter.hasNext() && !canceled() && processed < LIMIT) {
65+
Run<?, ?> build = iter.next();
6466
JSONObject element = new JSONObject();
6567
calculate(build, element);
6668
synchronized (this) {

0 commit comments

Comments
 (0)