Skip to content

Commit 8c29363

Browse files
jglicksamatdav
authored andcommitted
[JENKINS-35098] Disable AutoBrowserHolder by default to improve the changelog rendering performance (jenkinsci#2371)
* [FIXED JENKINS-35098] Deleting AutoBrowserHolder. * Normalizing form binding scheme for AbstractProject.scm. * At @oleg-nenashev’s insistence, restoring AutoBrowserHolder, though not using it by default. * Using SystemProperties at @oleg-nenashev’s recommendation.
1 parent 84d0c90 commit 8c29363

File tree

6 files changed

+36
-24
lines changed

6 files changed

+36
-24
lines changed

core/src/main/java/hudson/scm/AutoBrowserHolder.java

+2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
*
3838
* <p>
3939
* This class makes such tracking easy by hiding this logic.
40+
* @deprecated Disabled by default: JENKINS-35098
4041
*/
42+
@Deprecated
4143
final class AutoBrowserHolder {
4244
private int cacheGeneration;
4345
private RepositoryBrowser cache;

core/src/main/java/hudson/scm/NullSCM.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@
3131
import hudson.model.TaskListener;
3232
import java.io.File;
3333
import java.io.IOException;
34-
import net.sf.json.JSONObject;
3534
import org.jenkinsci.Symbol;
36-
import org.kohsuke.stapler.StaplerRequest;
35+
import org.kohsuke.stapler.DataBoundConstructor;
3736

3837
/**
3938
* No {@link SCM}.
4039
*
4140
* @author Kohsuke Kawaguchi
4241
*/
4342
public class NullSCM extends SCM {
43+
44+
@DataBoundConstructor
45+
public NullSCM() {}
46+
4447
@Override public SCMRevisionState calcRevisionsFromBuild(Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener) throws IOException, InterruptedException {
4548
return null;
4649
}
@@ -69,9 +72,5 @@ public DescriptorImpl() {
6972
return Messages.NullSCM_DisplayName();
7073
}
7174

72-
@Override
73-
public SCM newInstance(StaplerRequest req, JSONObject formData) throws FormException {
74-
return new NullSCM();
75-
}
7675
}
7776
}

core/src/main/java/hudson/scm/SCM.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import javax.annotation.Nonnull;
5959
import javax.annotation.Nullable;
6060
import jenkins.model.Jenkins;
61+
import jenkins.util.SystemProperties;
6162
import org.kohsuke.stapler.export.Exported;
6263
import org.kohsuke.stapler.export.ExportedBean;
6364

@@ -84,8 +85,13 @@
8485
*/
8586
@ExportedBean
8687
public abstract class SCM implements Describable<SCM>, ExtensionPoint {
88+
89+
/** JENKINS-35098: discouraged */
90+
@SuppressWarnings("FieldMayBeFinal")
91+
private static boolean useAutoBrowserHolder = SystemProperties.getBoolean(SCM.class.getName() + ".useAutoBrowserHolder");
8792
/**
8893
* Stores {@link AutoBrowserHolder}. Lazily created.
94+
* @deprecated Unused by default.
8995
*/
9096
private transient AutoBrowserHolder autoBrowserHolder;
9197

@@ -124,17 +130,21 @@ public String getType() {
124130
* Returns the applicable {@link RepositoryBrowser} for files
125131
* controlled by this {@link SCM}.
126132
* @see #guessBrowser
127-
* @see SCMDescriptor#isBrowserReusable
128133
*/
134+
@SuppressWarnings("deprecation")
129135
@Exported(name="browser")
130136
public final @CheckForNull RepositoryBrowser<?> getEffectiveBrowser() {
131137
RepositoryBrowser<?> b = getBrowser();
132138
if(b!=null)
133139
return b;
134-
if(autoBrowserHolder==null)
135-
autoBrowserHolder = new AutoBrowserHolder(this);
136-
return autoBrowserHolder.get();
137-
140+
if (useAutoBrowserHolder) {
141+
if (autoBrowserHolder == null) {
142+
autoBrowserHolder = new AutoBrowserHolder(this);
143+
}
144+
return autoBrowserHolder.get();
145+
} else {
146+
return guessBrowser();
147+
}
138148
}
139149

140150
/**

core/src/main/java/hudson/scm/SCMDescriptor.java

+4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ public abstract class SCMDescriptor<T extends SCM> extends Descriptor<SCM> {
5353
* This is used to invalidate cache of {@link SCM#getEffectiveBrowser}. Due to the lack of synchronization and serialization,
5454
* this field doesn't really count the # of instances created to date,
5555
* but it's good enough for the cache invalidation.
56+
* @deprecated No longer used by default.
5657
*/
58+
@Deprecated
5759
public volatile int generation = 1;
5860

5961
protected SCMDescriptor(Class<T> clazz, Class<? extends RepositoryBrowser> repositoryBrowser) {
@@ -102,7 +104,9 @@ public void load() {
102104
* @return
103105
* true if the two given SCM configurations are similar enough
104106
* that they can reuse {@link RepositoryBrowser} between them.
107+
* @deprecated No longer used by default. {@link SCM#getKey} could be used to implement similar features if needed.
105108
*/
109+
@Deprecated
106110
public boolean isBrowserReusable(T x, T y) {
107111
return false;
108112
}

core/src/main/java/hudson/scm/SCMS.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,11 @@ public class SCMS {
5454
* @param target
5555
* The project for which this SCM is configured to.
5656
*/
57+
@SuppressWarnings("deprecation")
5758
public static SCM parseSCM(StaplerRequest req, AbstractProject target) throws FormException, ServletException {
58-
String scm = req.getParameter("scm");
59-
if(scm==null) return new NullSCM();
60-
61-
int scmidx = Integer.parseInt(scm);
62-
SCMDescriptor<?> d = SCM._for(target).get(scmidx);
63-
d.generation++;
64-
return d.newInstance(req, req.getSubmittedForm().getJSONObject("scm"));
59+
SCM scm = req.bindJSON(SCM.class, req.getSubmittedForm().getJSONObject("scm"));
60+
scm.getDescriptor().generation++;
61+
return scm;
6562
}
6663

6764
/**

core/src/main/resources/lib/hudson/project/config-scm.jelly

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ THE SOFTWARE.
2626
<?jelly escape-by-default='true'?>
2727
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
2828
<f:section title="${%Source Code Management}">
29-
<j:set var="scms" value="${h.getSCMDescriptors(it)}" />
30-
<j:forEach var="idx" begin="0" end="${size(scms)-1}">
31-
<j:set var="descriptor" value="${scms[idx]}" />
29+
<!-- Could use f:descriptorRadioList were it not for scm/scmd compatibility code; pending JENKINS-20959 would not help with performance -->
30+
<j:forEach var="descriptor" items="${h.getSCMDescriptors(instance)}" varStatus="loop">
3231
<j:set var="scmd" value="${descriptor}" /><!-- backward compatibility with <1.238 -->
33-
<f:radioBlock name="scm" value="${idx}" title="${scmd.displayName}" checked="${it.scm.descriptor==scmd}">
34-
<j:set var="instance" value="${it.scm.descriptor==descriptor ? it.scm : null}"/>
32+
<f:radioBlock name="scm" help="${descriptor.helpFile}" value="${loop.index}" title="${descriptor.displayName}" checked="${instance.scm.descriptor == descriptor}">
33+
<j:set var="instance" value="${instance.scm.descriptor == descriptor ? it.scm : null}"/>
3534
<j:set var="scm" value="${instance}" /><!-- backward compatibility with <1.238 -->
36-
<st:include from="${scmd}" page="${scmd.configPage}"/>
35+
<f:class-entry descriptor="${descriptor}" />
36+
<st:include from="${descriptor}" page="${descriptor.configPage}" optional="true"/>
3737
</f:radioBlock>
3838
</j:forEach>
3939
</f:section>

0 commit comments

Comments
 (0)