2727import hudson .model .Run ;
2828import hudson .util .RunList ;
2929import java .util .ArrayList ;
30+ import java .util .Iterator ;
3031import java .util .List ;
3132import jenkins .util .ProgressiveRendering ;
33+ import jenkins .util .SystemProperties ;
3234import net .sf .json .JSON ;
3335import net .sf .json .JSONArray ;
3436import 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