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:
		| @@ -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); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Shawn Pearce
					Shawn Pearce