Replace most ChangeAccess queries with searches
Use the secondary index rather than depending on SQL indexes, which will not be available in a notedb world. For the most part this change is pretty straightforward, as the interface for InternalChangeQuery is almost the same as for ChangeAccess. It also provides a bit more functionality, such as limiting the results. By default, all of these queries should bypass visibility checks, since things like the submit queue necessarily need to see everything. Even if it is properly running as InternalUser and that is hard-coded to have visibility, it is simpler to just bypass the checks entirely. The biggest complication comes from converting callers that previously opened a new ReviewDb in a try/finally block and called a ChangeAccess method directly from that. In the InternalChangeQuery model, Provider<ReviewDb> needs to be injected, so we need to set the ThreadLocalRequestContext with the manually-opened DB. To simplify this code, add an AutoCloseable RequestContext implementation. To save future schema churn, this change does not include a schema change to drop the indexes. Change-Id: I99de8a2cf2aba01971059b89df33b1676cd8546e
This commit is contained in:
@@ -17,9 +17,11 @@ package com.google.gerrit.server.args4j;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gerrit.server.query.change.InternalChangeQuery;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
@@ -30,17 +32,16 @@ import org.kohsuke.args4j.spi.Parameters;
|
||||
import org.kohsuke.args4j.spi.Setter;
|
||||
|
||||
public class ChangeIdHandler extends OptionHandler<Change.Id> {
|
||||
|
||||
@Inject
|
||||
private ReviewDb db;
|
||||
private final Provider<InternalChangeQuery> queryProvider;
|
||||
|
||||
@Inject
|
||||
public ChangeIdHandler(
|
||||
final ReviewDb db,
|
||||
// TODO(dborowitz): Not sure whether this is injectable here.
|
||||
Provider<InternalChangeQuery> queryProvider,
|
||||
@Assisted final CmdLineParser parser, @Assisted final OptionDef option,
|
||||
@Assisted final Setter<Change.Id> setter) {
|
||||
super(parser, option, setter);
|
||||
this.db = db;
|
||||
this.queryProvider = queryProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,8 +59,8 @@ public class ChangeIdHandler extends OptionHandler<Change.Id> {
|
||||
final Project.NameKey project = new Project.NameKey(tokens[0]);
|
||||
final Branch.NameKey branch =
|
||||
new Branch.NameKey(project, "refs/heads/" + tokens[1]);
|
||||
for (final Change change : db.changes().byBranchKey(branch, key)) {
|
||||
setter.addValue(change.getId());
|
||||
for (final ChangeData cd : queryProvider.get().byBranchKey(branch, key)) {
|
||||
setter.addValue(cd.getId());
|
||||
return 1;
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
||||
Reference in New Issue
Block a user