Fix ChangeIndexer to be runnable from REST API

The request scope should not be relied upon to obtain a database
connection.  The ChangeIndexer does not need the CurrentUser, it just
expects a Provider<ReviewDb> to work.  Temporarily obtain a ReviewDb
when the task starts executing, pass it through as part of the
RequestContext, and release the connection when the task is done.

Change-Id: I3ebcb634bfb7112756cdb2ad49f3ead83cd1b4d7
This commit is contained in:
Shawn Pearce
2013-06-25 12:23:42 -06:00
parent 24f3a986d1
commit a5ca2095e4
5 changed files with 40 additions and 49 deletions

View File

@@ -32,7 +32,6 @@ import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
import com.google.gerrit.server.index.ChangeIndexer;
import com.google.gerrit.server.patch.PatchSetInfoFactory;
import com.google.gerrit.server.project.RefControl;
import com.google.gerrit.server.util.RequestScopePropagator;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
@@ -62,7 +61,6 @@ public class ChangeInserter {
private final RevCommit commit;
private final PatchSetInfo patchSetInfo;
private RequestScopePropagator requestScopePropagator;
private ChangeMessage changeMessage;
private Set<Account.Id> reviewers;
@@ -99,11 +97,6 @@ public class ChangeInserter {
ChangeUtil.computeSortKey(change);
}
public ChangeInserter setRequestScopePropagator(RequestScopePropagator rsp) {
requestScopePropagator = rsp;
return this;
}
public ChangeInserter setMessage(ChangeMessage changeMessage) {
this.changeMessage = changeMessage;
return this;
@@ -147,7 +140,7 @@ public class ChangeInserter {
db.changeMessages().insert(Collections.singleton(changeMessage));
}
indexer.index(change, requestScopePropagator);
indexer.index(change);
gitRefUpdated.fire(change.getProject(), patchSet.getRefName(),
ObjectId.zeroId(), commit);
hooks.doPatchsetCreatedHook(change, patchSet, db);