提交 a0262d2f 编写于 作者: O Oleg Nenashev 提交者: GitHub

[JENKINS-40435] - Use BulkChange when processing config changes in Job#doConfigSubmit. (#2664)

When an empty Freestyle job config gets submitted in the default configuration of Jenkins 2.35, the data is being saved to the disk *8 times*. All of them happen in this code: https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/model/Job.java#L1227-L1246

* setDisplayName
* Project#getBuildWrappersList().rebuild (onModified handler)
* Project#getBuilderList().rebuild (onModified handler)
* Project#getPublisherList().rebuild (onModified handler)
* AbstractProject#makeDisabled
* AbstractProject#setScm
* AbstractProject#triggers.replaceBy
* final save()

There is not so much sense to save partial configurations to the disk due to the risk of data inconsistency there. This change just wraps the config submission section of the job into the BulkChange clause.
上级 a1258c00
......@@ -1224,26 +1224,27 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
JSONObject json = req.getSubmittedForm();
try {
setDisplayName(json.optString("displayNameOrNull"));
try (BulkChange bc = new BulkChange(this)) {
setDisplayName(json.optString("displayNameOrNull"));
logRotator = null;
logRotator = null;
DescribableList<JobProperty<?>, JobPropertyDescriptor> t = new DescribableList<JobProperty<?>, JobPropertyDescriptor>(NOOP,getAllProperties());
JSONObject jsonProperties = json.optJSONObject("properties");
if (jsonProperties != null) {
t.rebuild(req,jsonProperties,JobPropertyDescriptor.getPropertyDescriptors(Job.this.getClass()));
} else {
t.clear();
}
properties.clear();
for (JobProperty p : t) {
p.setOwner(this);
properties.add(p);
}
submit(req, rsp);
DescribableList<JobProperty<?>, JobPropertyDescriptor> t = new DescribableList<JobProperty<?>, JobPropertyDescriptor>(NOOP,getAllProperties());
JSONObject jsonProperties = json.optJSONObject("properties");
if (jsonProperties != null) {
t.rebuild(req,jsonProperties,JobPropertyDescriptor.getPropertyDescriptors(Job.this.getClass()));
} else {
t.clear();
}
properties.clear();
for (JobProperty p : t) {
p.setOwner(this);
properties.add(p);
}
save();
submit(req, rsp);
bc.commit();
}
ItemListener.fireOnUpdated(this);
String newName = req.getParameter("name");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册