Skip to content

Commit 7f11e76

Browse files
Dmytro Ukhlovdukhlov
authored andcommitted
Fix "Zeno’s paradox" like logic of the progress calculation.
1 parent 40e88da commit 7f11e76

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
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;
3233
import net.sf.json.JSON;
@@ -46,7 +47,9 @@ public abstract class RunListProgressiveRendering extends ProgressiveRendering {
4647
* The first increment will be sized as if this many runs will be in the total,
4748
* but then like Zeno’s paradox we will never seem to finish until we actually do.
4849
*/
49-
private static final double MAX_LIKELY_RUNS = 20;
50+
private static final double MAX_LIKELY_RUNS = 20; // if (MAX_LIKELY_RUNS / 2) runs are processed, progress is 0.5
51+
private static final int RUN_LIMIT = 1000; // Limit is need because UI doesn't have a pagination
52+
5053
private final List<JSONObject> results = new ArrayList<>();
5154
private Iterable<? extends Run<?, ?>> builds;
5255

@@ -56,18 +59,17 @@ public void setBuilds(Iterable<? extends Run<?, ?>> builds) {
5659
}
5760

5861
@Override protected void compute() throws Exception {
59-
double decay = 1;
60-
for (Run<?, ?> build : builds) {
61-
if (canceled()) {
62-
return;
63-
}
62+
int processed = 0;
63+
Iterator<? extends Run<?, ?>> iter = builds.iterator();
64+
while (!canceled() && iter.hasNext() && processed < RUN_LIMIT) {
65+
Run<?, ?> build = iter.next();
6466
JSONObject element = new JSONObject();
6567
calculate(build, element);
6668
synchronized (this) {
6769
results.add(element);
6870
}
69-
decay *= 1 - 1 / MAX_LIKELY_RUNS;
70-
progress(1 - decay);
71+
processed++;
72+
progress(processed / (processed + MAX_LIKELY_RUNS / 2.0));
7173
}
7274
}
7375

0 commit comments

Comments
 (0)