Skip to content

Commit

Permalink
[JENKINS-19446] Saving Jenkins configuration in onRenamed/onDeleted i…
Browse files Browse the repository at this point in the history
…s often overkill.

This is already handled by ListView.Listener (other kinds of views are now responsible for their own listeners).
And handled better—if there are no actual changes
(because you have no such views, or they do not mention this job), there is no need to save.
Also moving the actual saving in those remaining cases out of the lock on the ListView itself, just in case.
  • Loading branch information
jglick committed Feb 28, 2014
1 parent f3558e1 commit 3aa0dd5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
28 changes: 16 additions & 12 deletions core/src/main/java/hudson/model/ListView.java
Expand Up @@ -397,18 +397,20 @@ public static List<ListViewColumn> getDefaultColumns() {
for (View v : vg.getViews()) {
if (v instanceof ListView) {
ListView lv = (ListView) v;
boolean needsSave;
synchronized (lv) {
Set<String> oldJobNames = new HashSet<String>(lv.jobNames);
lv.jobNames.clear();
for (String oldName : oldJobNames) {
lv.jobNames.add(Items.computeRelativeNamesAfterRenaming(oldFullName, newFullName, oldName, vg.getItemGroup()));
}
if (!oldJobNames.equals(lv.jobNames)) {
try {
g.save();
} catch (IOException x) {
Logger.getLogger(ListView.class.getName()).log(Level.WARNING, null, x);
}
needsSave = !oldJobNames.equals(lv.jobNames);
}
if (needsSave) { // do not hold ListView lock at the time
try {
g.save();
} catch (IOException x) {
Logger.getLogger(ListView.class.getName()).log(Level.WARNING, null, x);
}
}
}
Expand All @@ -423,13 +425,15 @@ public static List<ListViewColumn> getDefaultColumns() {
for (View v : vg.getViews()) {
if (v instanceof ListView) {
ListView lv = (ListView) v;
boolean needsSave;
synchronized (lv) {
if (lv.jobNames.remove(item.getRelativeNameFrom(vg.getItemGroup()))) {
try {
g.save();
} catch (IOException x) {
Logger.getLogger(ListView.class.getName()).log(Level.WARNING, null, x);
}
needsSave = lv.jobNames.remove(item.getRelativeNameFrom(vg.getItemGroup()));
}
if (needsSave) {
try {
g.save();
} catch (IOException x) {
Logger.getLogger(ListView.class.getName()).log(Level.WARNING, null, x);
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/java/jenkins/model/Jenkins.java
Expand Up @@ -2440,7 +2440,6 @@ public void onRenamed(TopLevelItem job, String oldName, String newName) throws I
// For compatibility with old views:
for (View v : views)
v.onJobRenamed(job, oldName, newName);
save();
}

/**
Expand All @@ -2453,7 +2452,6 @@ public void onDeleted(TopLevelItem item) throws IOException {
// For compatibility with old views:
for (View v : views)
v.onJobRenamed(item, item.getName(), null);
save();
}

@Override public boolean canAdd(TopLevelItem item) {
Expand Down

0 comments on commit 3aa0dd5

Please sign in to comment.