Merge branch 'stable-2.10'

* stable-2.10:
  Remove uneeded dependency in ChangesCollection
  Delete a change from the index when it is not in the DB

Change-Id: I02a4773dd581c29704a7cc45c5225258d657f836
This commit is contained in:
Dave Borowitz
2014-11-12 10:13:32 -08:00
8 changed files with 83 additions and 6 deletions

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.server.change;
import com.google.common.primitives.Ints;
import com.google.gerrit.extensions.registration.DynamicMap;
import com.google.gerrit.extensions.restapi.AcceptsPost;
import com.google.gerrit.extensions.restapi.IdString;
@@ -25,6 +26,7 @@ import com.google.gerrit.extensions.restapi.TopLevelResource;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.index.ChangeIndexer;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.query.change.QueryChanges;
@@ -33,6 +35,7 @@ import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.io.IOException;
import java.util.List;
@Singleton
@@ -45,6 +48,7 @@ public class ChangesCollection implements
private final DynamicMap<RestView<ChangeResource>> views;
private final ChangeUtil changeUtil;
private final CreateChange createChange;
private final ChangeIndexer changeIndexer;
@Inject
ChangesCollection(
@@ -53,13 +57,15 @@ public class ChangesCollection implements
Provider<QueryChanges> queryFactory,
DynamicMap<RestView<ChangeResource>> views,
ChangeUtil changeUtil,
CreateChange createChange) {
CreateChange createChange,
ChangeIndexer changeIndexer) {
this.user = user;
this.changeControlFactory = changeControlFactory;
this.queryFactory = queryFactory;
this.views = views;
this.changeUtil = changeUtil;
this.createChange = createChange;
this.changeIndexer = changeIndexer;
}
@Override
@@ -76,6 +82,16 @@ public class ChangesCollection implements
public ChangeResource parse(TopLevelResource root, IdString id)
throws ResourceNotFoundException, OrmException {
List<Change> changes = changeUtil.findChanges(id.encoded());
if (changes.isEmpty()) {
Integer changeId = Ints.tryParse(id.get());
if (changeId != null) {
try {
changeIndexer.delete(changeId);
} catch (IOException e) {
throw new ResourceNotFoundException(id.get(), e);
}
}
}
if (changes.size() != 1) {
throw new ResourceNotFoundException(id);
}