Skip to content

Commit ddd8abe

Browse files
author
Dmytro Ukhlov
committed
Fix "Zeno’s paradox" like logic of the progress calculation.
1 parent 596773f commit ddd8abe

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
package jenkins.widgets;
2626

27+
import com.google.common.collect.Iterables;
2728
import hudson.model.Run;
2829
import hudson.util.RunList;
2930
import java.util.ArrayList;
@@ -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,8 +59,8 @@ 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) {
62+
int processed = 0;
63+
for (Run<?, ?> build : Iterables.limit(builds, RUN_LIMIT)) {
6164
if (canceled()) {
6265
return;
6366
}
@@ -66,8 +69,8 @@ public void setBuilds(Iterable<? extends Run<?, ?>> builds) {
6669
synchronized (this) {
6770
results.add(element);
6871
}
69-
decay *= 1 - 1 / MAX_LIKELY_RUNS;
70-
progress(1 - decay);
72+
processed++;
73+
progress(processed / (processed + MAX_LIKELY_RUNS / 2.0));
7174
}
7275
}
7376

0 commit comments

Comments
 (0)