Remove ReviewDb from ChangeData

Propagate the removal out to some downstream interfaces as well.
Ironically, in at least one case, we needed to *add* a
Provider<ReviewDb> to a class, since it was using ChangeData#db() as the
argument to another method which hasn't yet had this argument removed.

Change-Id: I42b1609e402d7dd552ea67197d21c28051261ee8
This commit is contained in:
Dave Borowitz
2018-12-14 13:25:26 -08:00
parent b17c00ab5e
commit 5fef1eb3a0
59 changed files with 132 additions and 304 deletions

View File

@@ -26,7 +26,6 @@ import com.google.gerrit.extensions.client.ChangeKind;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.PatchSetApproval;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.change.ChangeKindCache;
import com.google.gerrit.server.change.LabelNormalizer;
import com.google.gerrit.server.notedb.ChangeNotes;
@@ -74,18 +73,12 @@ public class ApprovalCopier {
}
Iterable<PatchSetApproval> getForPatchSet(
ReviewDb db,
ChangeNotes notes,
PatchSet.Id psId,
@Nullable RevWalk rw,
@Nullable Config repoConfig)
ChangeNotes notes, PatchSet.Id psId, @Nullable RevWalk rw, @Nullable Config repoConfig)
throws OrmException {
return getForPatchSet(
db, notes, psId, rw, repoConfig, Collections.<PatchSetApproval>emptyList());
return getForPatchSet(notes, psId, rw, repoConfig, Collections.<PatchSetApproval>emptyList());
}
Iterable<PatchSetApproval> getForPatchSet(
ReviewDb db,
ChangeNotes notes,
PatchSet.Id psId,
@Nullable RevWalk rw,
@@ -96,11 +89,10 @@ public class ApprovalCopier {
if (ps == null) {
return Collections.emptyList();
}
return getForPatchSet(db, notes, ps, rw, repoConfig, dontCopy);
return getForPatchSet(notes, ps, rw, repoConfig, dontCopy);
}
private Iterable<PatchSetApproval> getForPatchSet(
ReviewDb db,
ChangeNotes notes,
PatchSet ps,
@Nullable RevWalk rw,
@@ -108,7 +100,7 @@ public class ApprovalCopier {
Iterable<PatchSetApproval> dontCopy)
throws OrmException {
requireNonNull(ps, "ps should not be null");
ChangeData cd = changeDataFactory.create(db, notes);
ChangeData cd = changeDataFactory.create(notes);
try {
ProjectState project = projectCache.checkedGet(cd.change().getDest().getParentKey());
ListMultimap<PatchSet.Id, PatchSetApproval> all = cd.approvals();

View File

@@ -350,24 +350,19 @@ public class ApprovalsUtil {
}
public Iterable<PatchSetApproval> byPatchSet(
ReviewDb db,
ChangeNotes notes,
PatchSet.Id psId,
@Nullable RevWalk rw,
@Nullable Config repoConfig)
ChangeNotes notes, PatchSet.Id psId, @Nullable RevWalk rw, @Nullable Config repoConfig)
throws OrmException {
return copier.getForPatchSet(db, notes, psId, rw, repoConfig);
return copier.getForPatchSet(notes, psId, rw, repoConfig);
}
public Iterable<PatchSetApproval> byPatchSetUser(
ReviewDb db,
ChangeNotes notes,
PatchSet.Id psId,
Account.Id accountId,
@Nullable RevWalk rw,
@Nullable Config repoConfig)
throws OrmException {
return filterApprovals(byPatchSet(db, notes, psId, rw, repoConfig), accountId);
return filterApprovals(byPatchSet(notes, psId, rw, repoConfig), accountId);
}
public PatchSetApproval getSubmitter(ChangeNotes notes, PatchSet.Id c) {

View File

@@ -28,7 +28,6 @@ import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.PatchSetApproval;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RevId;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.notedb.ChangeUpdate;
@@ -52,18 +51,15 @@ import org.eclipse.jgit.revwalk.RevWalk;
public class PatchSetUtil {
private final Provider<ApprovalsUtil> approvalsUtilProvider;
private final ProjectCache projectCache;
private final Provider<ReviewDb> dbProvider;
private final GitRepositoryManager repoManager;
@Inject
PatchSetUtil(
Provider<ApprovalsUtil> approvalsUtilProvider,
ProjectCache projectCache,
Provider<ReviewDb> dbProvider,
GitRepositoryManager repoManager) {
this.approvalsUtilProvider = approvalsUtilProvider;
this.projectCache = projectCache;
this.dbProvider = dbProvider;
this.repoManager = repoManager;
}
@@ -159,7 +155,7 @@ public class PatchSetUtil {
ApprovalsUtil approvalsUtil = approvalsUtilProvider.get();
for (PatchSetApproval ap :
approvalsUtil.byPatchSet(dbProvider.get(), notes, change.currentPatchSetId(), null, null)) {
approvalsUtil.byPatchSet(notes, change.currentPatchSetId(), null, null)) {
LabelType type = projectState.getLabelTypes(notes).byLabel(ap.getLabel());
if (type != null
&& ap.getValue() == 1

View File

@@ -35,7 +35,6 @@ import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.config.AllUsersName;
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
@@ -167,7 +166,6 @@ public class StarredChangesUtil {
private final GitRepositoryManager repoManager;
private final GitReferenceUpdated gitRefUpdated;
private final AllUsersName allUsers;
private final Provider<ReviewDb> dbProvider;
private final Provider<PersonIdent> serverIdent;
private final ChangeIndexer indexer;
private final Provider<InternalChangeQuery> queryProvider;
@@ -177,14 +175,12 @@ public class StarredChangesUtil {
GitRepositoryManager repoManager,
GitReferenceUpdated gitRefUpdated,
AllUsersName allUsers,
Provider<ReviewDb> dbProvider,
@GerritPersonIdent Provider<PersonIdent> serverIdent,
ChangeIndexer indexer,
Provider<InternalChangeQuery> queryProvider) {
this.repoManager = repoManager;
this.gitRefUpdated = gitRefUpdated;
this.allUsers = allUsers;
this.dbProvider = dbProvider;
this.serverIdent = serverIdent;
this.indexer = indexer;
this.queryProvider = queryProvider;
@@ -229,7 +225,7 @@ public class StarredChangesUtil {
updateLabels(repo, refName, old.objectId(), labels);
}
indexer.index(dbProvider.get(), project, changeId);
indexer.index(project, changeId);
return ImmutableSortedSet.copyOf(labels);
} catch (IOException e) {
throw new OrmException(
@@ -259,7 +255,7 @@ public class StarredChangesUtil {
changeId.get(), command.getRefName(), command.getResult()));
}
}
indexer.index(dbProvider.get(), project, changeId);
indexer.index(project, changeId);
} catch (IOException e) {
throw new OrmException(String.format("Unstar change %d failed", changeId.get()), e);
}

View File

@@ -268,11 +268,11 @@ public class ChangeJson {
}
public ChangeInfo format(ChangeResource rsrc) throws OrmException {
return format(changeDataFactory.create(db.get(), rsrc.getNotes()));
return format(changeDataFactory.create(rsrc.getNotes()));
}
public ChangeInfo format(Change change) throws OrmException {
return format(changeDataFactory.create(db.get(), change));
return format(changeDataFactory.create(change));
}
public ChangeInfo format(Project.NameKey project, Change.Id id) throws OrmException {
@@ -284,7 +284,7 @@ public class ChangeJson {
}
public ChangeInfo format(RevisionResource rsrc) throws OrmException {
ChangeData cd = changeDataFactory.create(db.get(), rsrc.getNotes());
ChangeData cd = changeDataFactory.create(rsrc.getNotes());
return format(cd, Optional.of(rsrc.getPatchSet().getId()), true, ChangeInfo::new);
}
@@ -328,10 +328,9 @@ public class ChangeJson {
if (!has(CHECK)) {
throw e;
}
return checkOnly(changeDataFactory.create(db.get(), project, id), changeInfoSupplier);
return checkOnly(changeDataFactory.create(project, id), changeInfoSupplier);
}
return format(
changeDataFactory.create(db.get(), notes), Optional.empty(), true, changeInfoSupplier);
return format(changeDataFactory.create(notes), Optional.empty(), true, changeInfoSupplier);
}
private static Collection<SubmitRequirementInfo> requirementsFor(ChangeData cd) {
@@ -496,7 +495,7 @@ public class ChangeJson {
// If any problems were fixed, the ChangeData needs to be reloaded.
for (ProblemInfo p : out.problems) {
if (p.status == ProblemInfo.Status.FIXED) {
cd = changeDataFactory.create(cd.db(), cd.project(), cd.getId());
cd = changeDataFactory.create(cd.project(), cd.getId());
break;
}
}

View File

@@ -115,7 +115,7 @@ public class ChangeKindCacheImpl implements ChangeKindCache {
@Override
public ChangeKind getChangeKind(ReviewDb db, Change change, PatchSet patch) {
return getChangeKindInternal(this, db, change, patch, changeDataFactory, repoManager);
return getChangeKindInternal(this, change, patch, changeDataFactory, repoManager);
}
@Override
@@ -351,7 +351,7 @@ public class ChangeKindCacheImpl implements ChangeKindCache {
@Override
public ChangeKind getChangeKind(ReviewDb db, Change change, PatchSet patch) {
return getChangeKindInternal(this, db, change, patch, changeDataFactory, repoManager);
return getChangeKindInternal(this, change, patch, changeDataFactory, repoManager);
}
@Override
@@ -406,7 +406,6 @@ public class ChangeKindCacheImpl implements ChangeKindCache {
private static ChangeKind getChangeKindInternal(
ChangeKindCache cache,
ReviewDb db,
Change change,
PatchSet patch,
ChangeData.Factory changeDataFactory,
@@ -420,7 +419,7 @@ public class ChangeKindCacheImpl implements ChangeKindCache {
RevWalk rw = new RevWalk(repo)) {
kind =
getChangeKindInternal(
cache, rw, repo.getConfig(), changeDataFactory.create(db, change), patch);
cache, rw, repo.getConfig(), changeDataFactory.create(change), patch);
} catch (IOException e) {
// Do nothing; assume we have a complex change
logger.atWarning().withCause(e).log(

View File

@@ -263,7 +263,6 @@ public class LabelsJson {
Map<String, Short> result = new HashMap<>();
for (PatchSetApproval psa :
approvalsUtil.byPatchSetUser(
db.get(),
lazyLoad ? cd.notes() : notesFactory.createFromIndexedChange(cd.change()),
cd.change().currentPatchSetId(),
accountId,

View File

@@ -76,7 +76,7 @@ public class ReviewerJson {
ChangeData cd = null;
for (ReviewerResource rsrc : rsrcs) {
if (cd == null || !cd.getId().equals(rsrc.getChangeId())) {
cd = changeDataFactory.create(db.get(), rsrc.getChangeResource().getNotes());
cd = changeDataFactory.create(rsrc.getChangeResource().getNotes());
}
ReviewerInfo info;
if (rsrc.isByEmail()) {
@@ -105,7 +105,7 @@ public class ReviewerJson {
out,
reviewerAccountId,
cd,
approvalsUtil.byPatchSetUser(db.get(), cd.notes(), psId, reviewerAccountId, null, null));
approvalsUtil.byPatchSetUser(cd.notes(), psId, reviewerAccountId, null, null));
}
public ReviewerInfo format(

View File

@@ -628,6 +628,6 @@ public class ChangeEditModifier {
}
private void reindex(Change change) throws IOException {
indexer.index(reviewDb.get(), change);
indexer.index(change);
}
}

View File

@@ -230,7 +230,7 @@ public class ChangeEditUtil {
try (Repository repo = gitManager.openRepository(change.getProject())) {
deleteRef(repo, edit);
}
indexer.index(db.get(), change);
indexer.index(change);
}
private PatchSet getBasePatchSet(ChangeNotes notes, Ref ref) throws IOException {

View File

@@ -128,23 +128,7 @@ public class EventFactory {
* @param change
* @return object suitable for serialization to JSON
*/
public ChangeAttribute asChangeAttribute(Change change, ChangeNotes notes) {
try (ReviewDb db = schema.open()) {
return asChangeAttribute(db, change, notes);
} catch (OrmException e) {
logger.atSevere().withCause(e).log("Cannot open database connection");
return new ChangeAttribute();
}
}
/**
* Create a ChangeAttribute for the given change suitable for serialization to JSON.
*
* @param db Review database
* @param change
* @return object suitable for serialization to JSON
*/
public ChangeAttribute asChangeAttribute(ReviewDb db, Change change) {
public ChangeAttribute asChangeAttribute(Change change) {
ChangeAttribute a = new ChangeAttribute();
a.project = change.getProject().get();
a.branch = change.getDest().getShortName();
@@ -153,7 +137,7 @@ public class EventFactory {
a.number = change.getId().get();
a.subject = change.getSubject();
try {
a.commitMessage = changeDataFactory.create(db, change).commitMessage();
a.commitMessage = changeDataFactory.create(change).commitMessage();
} catch (Exception e) {
logger.atSevere().withCause(e).log(
"Error while getting full commit message for change %d", a.number);
@@ -171,14 +155,12 @@ public class EventFactory {
/**
* Create a ChangeAttribute for the given change suitable for serialization to JSON.
*
* @param db Review database
* @param change
* @param notes
* @return object suitable for serialization to JSON
*/
public ChangeAttribute asChangeAttribute(ReviewDb db, Change change, ChangeNotes notes)
throws OrmException {
ChangeAttribute a = asChangeAttribute(db, change);
public ChangeAttribute asChangeAttribute(Change change, ChangeNotes notes) throws OrmException {
ChangeAttribute a = asChangeAttribute(change);
Set<String> hashtags = notes.load().getHashtags();
if (!hashtags.isEmpty()) {
a.hashtags = new ArrayList<>(hashtags.size());

View File

@@ -154,7 +154,11 @@ public class StreamEventsApiListener
new Supplier<ChangeAttribute>() {
@Override
public ChangeAttribute get() {
return eventFactory.asChangeAttribute(change, notes);
try {
return eventFactory.asChangeAttribute(change, notes);
} catch (OrmException e) {
throw new RuntimeException(e);
}
}
});
}

View File

@@ -25,7 +25,6 @@ import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.GpgException;
import com.google.gerrit.server.account.AccountState;
import com.google.gerrit.server.change.ChangeJson;
@@ -35,7 +34,6 @@ import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.io.IOException;
import java.sql.Timestamp;
@@ -63,7 +61,6 @@ public class EventUtil {
}
private final ChangeData.Factory changeDataFactory;
private final Provider<ReviewDb> db;
private final ChangeJson.Factory changeJsonFactory;
private final RevisionJson.Factory revisionJsonFactory;
@@ -71,10 +68,8 @@ public class EventUtil {
EventUtil(
ChangeJson.Factory changeJsonFactory,
RevisionJson.Factory revisionJsonFactory,
ChangeData.Factory changeDataFactory,
Provider<ReviewDb> db) {
ChangeData.Factory changeDataFactory) {
this.changeDataFactory = changeDataFactory;
this.db = db;
this.changeJsonFactory = changeJsonFactory;
this.revisionJsonFactory = revisionJsonFactory;
}
@@ -92,7 +87,7 @@ public class EventUtil {
public RevisionInfo revisionInfo(Project.NameKey project, PatchSet ps)
throws OrmException, PatchListNotAvailableException, GpgException, IOException,
PermissionBackendException {
ChangeData cd = changeDataFactory.create(db.get(), project, ps.getId().getParentKey());
ChangeData cd = changeDataFactory.create(project, ps.getId().getParentKey());
return revisionJsonFactory.create(CHANGE_OPTIONS).getRevisionInfo(cd, ps);
}

View File

@@ -43,7 +43,6 @@ import com.google.gerrit.reviewdb.client.LabelId;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.PatchSet.Id;
import com.google.gerrit.reviewdb.client.PatchSetApproval;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.ApprovalsUtil;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.config.GerritServerConfig;
@@ -58,7 +57,6 @@ import com.google.gerrit.server.submit.MergeIdenticalTreeException;
import com.google.gerrit.server.submit.MergeSorter;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
import java.io.IOException;
@@ -162,7 +160,6 @@ public class MergeUtil {
MergeUtil create(ProjectState project, boolean useContentMerge);
}
private final Provider<ReviewDb> db;
private final IdentifiedUser.GenericFactory identifiedUserFactory;
private final UrlFormatter urlFormatter;
private final ApprovalsUtil approvalsUtil;
@@ -174,7 +171,6 @@ public class MergeUtil {
@AssistedInject
MergeUtil(
@GerritServerConfig Config serverConfig,
Provider<ReviewDb> db,
IdentifiedUser.GenericFactory identifiedUserFactory,
UrlFormatter urlFormatter,
ApprovalsUtil approvalsUtil,
@@ -182,7 +178,6 @@ public class MergeUtil {
@Assisted ProjectState project) {
this(
serverConfig,
db,
identifiedUserFactory,
urlFormatter,
approvalsUtil,
@@ -194,14 +189,12 @@ public class MergeUtil {
@AssistedInject
MergeUtil(
@GerritServerConfig Config serverConfig,
Provider<ReviewDb> db,
IdentifiedUser.GenericFactory identifiedUserFactory,
UrlFormatter urlFormatter,
ApprovalsUtil approvalsUtil,
@Assisted ProjectState project,
PluggableCommitMessageGenerator commitMessageGenerator,
@Assisted boolean useContentMerge) {
this.db = db;
this.identifiedUserFactory = identifiedUserFactory;
this.urlFormatter = urlFormatter;
this.approvalsUtil = approvalsUtil;
@@ -598,7 +591,7 @@ public class MergeUtil {
private Iterable<PatchSetApproval> safeGetApprovals(ChangeNotes notes, PatchSet.Id psId) {
try {
return approvalsUtil.byPatchSet(db.get(), notes, psId, null, null);
return approvalsUtil.byPatchSet(notes, psId, null, null);
} catch (OrmException e) {
logger.atSevere().withCause(e).log("Can't read approval records for %s", psId);
return Collections.emptyList();

View File

@@ -24,7 +24,6 @@ import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.ReviewerSet;
import com.google.gerrit.server.cache.CacheModule;
import com.google.gerrit.server.index.change.ChangeField;
@@ -107,16 +106,15 @@ public class SearchingChangeCacheImpl implements GitReferenceUpdatedListener {
* <p>Returned changes only include the {@code Change} object (with id, branch) and the reviewers.
* Additional stored fields are not loaded from the index.
*
* @param db database handle to populate missing change data (probably unused).
* @param project project to read.
* @return list of known changes; empty if no changes.
*/
public List<ChangeData> getChangeData(ReviewDb db, Project.NameKey project) {
public List<ChangeData> getChangeData(Project.NameKey project) {
try {
List<CachedChange> cached = cache.get(project);
List<ChangeData> cds = new ArrayList<>(cached.size());
for (CachedChange cc : cached) {
ChangeData cd = changeDataFactory.create(db, cc.change());
ChangeData cd = changeDataFactory.create(cc.change());
cd.setReviewers(cc.reviewers());
cds.add(cd);
}

View File

@@ -255,7 +255,7 @@ public class ReplaceOp implements BatchUpdateOp {
groups = prevPs != null ? prevPs.getGroups() : ImmutableList.<String>of();
}
ChangeData cd = changeDataFactory.create(ctx.getDb(), ctx.getNotes());
ChangeData cd = changeDataFactory.create(ctx.getNotes());
oldRecipients = getRecipientsFromReviewers(cd.reviewers());
ChangeUpdate update = ctx.getUpdate(patchSetId);
@@ -452,7 +452,6 @@ public class ReplaceOp implements BatchUpdateOp {
if (!approvals.isEmpty()) {
for (PatchSetApproval a :
approvalsUtil.byPatchSetUser(
ctx.getDb(),
ctx.getNotes(),
priorPatchSetId,
ctx.getAccountId(),

View File

@@ -26,7 +26,6 @@ import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.AccountProperties;
import com.google.gerrit.server.config.AllProjectsName;
@@ -46,7 +45,6 @@ import com.google.gerrit.server.project.ProjectState;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.io.IOException;
import java.util.List;
import org.eclipse.jgit.errors.ConfigInvalidException;
@@ -268,18 +266,15 @@ public class MergeValidators {
AccountMergeValidator create();
}
private final Provider<ReviewDb> dbProvider;
private final AllUsersName allUsersName;
private final ChangeData.Factory changeDataFactory;
private final AccountValidator accountValidator;
@Inject
public AccountMergeValidator(
Provider<ReviewDb> dbProvider,
AllUsersName allUsersName,
ChangeData.Factory changeDataFactory,
AccountValidator accountValidator) {
this.dbProvider = dbProvider;
this.allUsersName = allUsersName;
this.changeDataFactory = changeDataFactory;
this.accountValidator = accountValidator;
@@ -301,7 +296,7 @@ public class MergeValidators {
ChangeData cd =
changeDataFactory.create(
dbProvider.get(), destProject.getProject().getNameKey(), patchSetId.getParentKey());
destProject.getProject().getNameKey(), patchSetId.getParentKey());
try {
if (!cd.currentFilePaths().contains(AccountProperties.ACCOUNT_CONFIG)) {
return;

View File

@@ -224,20 +224,20 @@ public class AllChangesIndexer extends SiteIndexer<Change.Id, ChangeData, Change
// It does mean that reindexing after invalidating the DiffSummary cache will be expensive,
// but the goal is to invalidate that cache as infrequently as we possibly can. And besides,
// we don't have concrete proof that improving packfile locality would help.
notesFactory.scan(repo, project).forEach(r -> index(db, r));
notesFactory.scan(repo, project).forEach(r -> index(r));
} catch (RepositoryNotFoundException rnfe) {
logger.atSevere().log(rnfe.getMessage());
}
return null;
}
private void index(ReviewDb db, ChangeNotesResult r) {
private void index(ChangeNotesResult r) {
if (r.error().isPresent()) {
fail("Failed to read change " + r.id() + " for indexing", true, r.error().get());
return;
}
try {
indexer.index(changeDataFactory.create(db, r.notes()));
indexer.index(changeDataFactory.create(r.notes()));
done.update(1);
verboseWriter.println("Reindexed change " + r.id());
} catch (RejectedExecutionException e) {

View File

@@ -223,22 +223,20 @@ public class ChangeIndexer {
/**
* Synchronously index a change.
*
* @param db review database.
* @param change change to index.
*/
public void index(ReviewDb db, Change change) throws IOException {
index(changeDataFactory.create(db, change));
public void index(Change change) throws IOException {
index(changeDataFactory.create(change));
}
/**
* Synchronously index a change.
*
* @param db review database.
* @param project the project to which the change belongs.
* @param changeId ID of the change to index.
*/
public void index(ReviewDb db, Project.NameKey project, Change.Id changeId) throws IOException {
index(changeDataFactory.create(db, project, changeId));
public void index(Project.NameKey project, Change.Id changeId) throws IOException {
index(changeDataFactory.create(project, changeId));
}
/**
@@ -369,7 +367,7 @@ public class ChangeIndexer {
@Override
public Void callImpl(Provider<ReviewDb> db) throws Exception {
ChangeData cd = changeDataFactory.create(db.get(), project, id);
ChangeData cd = changeDataFactory.create(project, id);
index(cd);
return null;
}
@@ -415,7 +413,7 @@ public class ChangeIndexer {
public Boolean callImpl(Provider<ReviewDb> db) throws Exception {
try {
if (stalenessChecker.isStale(id)) {
indexImpl(changeDataFactory.create(db.get(), project, id));
indexImpl(changeDataFactory.create(project, id));
return true;
}
} catch (Exception e) {

View File

@@ -27,7 +27,6 @@ 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.client.RefNames;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.account.AccountCache;
import com.google.gerrit.server.config.AllUsersName;
import com.google.gerrit.server.config.GerritServerConfig;
@@ -182,11 +181,10 @@ public class ReindexAfterRefUpdate implements GitReferenceUpdatedListener {
@Override
protected Void impl(RequestContext ctx) throws OrmException, IOException {
// Reload change, as some time may have passed since GetChanges.
ReviewDb db = ctx.getReviewDbProvider().get();
try {
Change c =
notesFactory.createChecked(new Project.NameKey(event.getProjectName()), id).getChange();
indexerFactory.create(executor, indexes).index(db, c);
indexerFactory.create(executor, indexes).index(c);
} catch (NoSuchChangeException e) {
indexerFactory.create(executor, indexes).delete(id);
}

View File

@@ -39,6 +39,7 @@ import com.google.gerrit.reviewdb.client.Comment;
import com.google.gerrit.reviewdb.client.PatchLineComment.Status;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.ApprovalsUtil;
import com.google.gerrit.server.ChangeMessagesUtil;
import com.google.gerrit.server.CommentsUtil;
@@ -84,6 +85,7 @@ import java.util.Set;
public class MailProcessor {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final Provider<ReviewDb> dbProvider;
private final Emails emails;
private final InboundEmailRejectionSender.Factory emailRejectionSender;
private final RetryHelper retryHelper;
@@ -102,6 +104,7 @@ public class MailProcessor {
@Inject
public MailProcessor(
Provider<ReviewDb> dbProvider,
Emails emails,
InboundEmailRejectionSender.Factory emailRejectionSender,
RetryHelper retryHelper,
@@ -117,6 +120,7 @@ public class MailProcessor {
CommentAdded commentAdded,
AccountCache accountCache,
UrlFormatter urlFormatter) {
this.dbProvider = dbProvider;
this.emails = emails;
this.emailRejectionSender = emailRejectionSender;
this.retryHelper = retryHelper;
@@ -259,7 +263,8 @@ public class MailProcessor {
}
Op o = new Op(new PatchSet.Id(cd.getId(), metadata.patchSet), parsedComments, message.id());
BatchUpdate batchUpdate = buf.create(cd.db(), project, ctx.getUser(), TimeUtil.nowTs());
BatchUpdate batchUpdate =
buf.create(dbProvider.get(), project, ctx.getUser(), TimeUtil.nowTs());
batchUpdate.addOp(cd.getId(), o);
batchUpdate.execute();
}
@@ -329,12 +334,7 @@ public class MailProcessor {
Map<String, Short> approvals = new HashMap<>();
approvalsUtil
.byPatchSetUser(
ctx.getDb(),
notes,
psId,
ctx.getAccountId(),
ctx.getRevWalk(),
ctx.getRepoView().getConfig())
notes, psId, ctx.getAccountId(), ctx.getRevWalk(), ctx.getRepoView().getConfig())
.forEach(a -> approvals.put(a.getLabel(), a.getValue()));
// Fire Gerrit event. Note that approvals can't be granted via email, so old and new approvals
// are always the same here.

View File

@@ -69,7 +69,7 @@ public abstract class ChangeEmail extends NotificationEmail {
protected static ChangeData newChangeData(
EmailArguments ea, Project.NameKey project, Change.Id id) {
return ea.changeDataFactory.create(ea.db.get(), project, id);
return ea.changeDataFactory.create(project, id);
}
protected final Change change;

View File

@@ -69,8 +69,7 @@ public class MergedSender extends ReplyToChangeSender {
Table<Account.Id, String, PatchSetApproval> pos = HashBasedTable.create();
Table<Account.Id, String, PatchSetApproval> neg = HashBasedTable.create();
for (PatchSetApproval ca :
args.approvalsUtil.byPatchSet(
args.db.get(), changeData.notes(), patchSet.getId(), null, null)) {
args.approvalsUtil.byPatchSet(changeData.notes(), patchSet.getId(), null, null)) {
LabelType lt = labelTypes.byLabel(ca.getLabelId());
if (lt == null) {
continue;

View File

@@ -14,7 +14,6 @@
package com.google.gerrit.server.permissions;
import static com.google.common.base.Preconditions.checkState;
import static com.google.gerrit.server.permissions.DefaultPermissionMappings.labelPermissionName;
import static com.google.gerrit.server.permissions.LabelPermission.ForUser.ON_BEHALF_OF;
@@ -35,7 +34,6 @@ import com.google.gerrit.server.permissions.PermissionBackend.ForChange;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.util.Collection;
import java.util.EnumSet;
@@ -76,8 +74,8 @@ class ChangeControl {
this.notes = notes;
}
ForChange asForChange(@Nullable ChangeData cd, @Nullable Provider<ReviewDb> db) {
return new ForChangeImpl(cd, db);
ForChange asForChange(@Nullable ChangeData cd) {
return new ForChangeImpl(cd);
}
private CurrentUser getUser() {
@@ -93,8 +91,8 @@ class ChangeControl {
}
/** Can this user see this change? */
private boolean isVisible(ReviewDb db, @Nullable ChangeData cd) throws OrmException {
if (getChange().isPrivate() && !isPrivateVisible(db, cd)) {
private boolean isVisible(@Nullable ChangeData cd) throws OrmException {
if (getChange().isPrivate() && !isPrivateVisible(cd)) {
return false;
}
return refControl.isVisible();
@@ -157,9 +155,9 @@ class ChangeControl {
}
/** Is this user a reviewer for the change? */
private boolean isReviewer(ReviewDb db, @Nullable ChangeData cd) throws OrmException {
private boolean isReviewer(@Nullable ChangeData cd) throws OrmException {
if (getUser().isIdentifiedUser()) {
cd = cd != null ? cd : changeDataFactory.create(db, notes);
cd = cd != null ? cd : changeDataFactory.create(notes);
Collection<Account.Id> results = cd.reviewers().all();
return results.contains(getUser().getAccountId());
}
@@ -207,9 +205,9 @@ class ChangeControl {
|| getProjectControl().isAdmin();
}
private boolean isPrivateVisible(ReviewDb db, ChangeData cd) throws OrmException {
private boolean isPrivateVisible(ChangeData cd) throws OrmException {
return isOwner()
|| isReviewer(db, cd)
|| isReviewer(cd)
|| refControl.canPerform(Permission.VIEW_PRIVATE_CHANGES)
|| getUser().isInternalUser();
}
@@ -219,26 +217,20 @@ class ChangeControl {
private Map<String, PermissionRange> labels;
private String resourcePath;
ForChangeImpl(@Nullable ChangeData cd, @Nullable Provider<ReviewDb> db) {
ForChangeImpl(@Nullable ChangeData cd) {
this.cd = cd;
this.db = db;
}
private ReviewDb db() {
if (db != null) {
return db.get();
} else if (cd != null) {
return cd.db();
} else {
return null;
}
return null;
}
private ChangeData changeData() {
if (cd == null) {
ReviewDb reviewDb = db();
checkState(reviewDb != null, "need ReviewDb");
cd = changeDataFactory.create(reviewDb, notes);
cd = changeDataFactory.create(notes);
}
return cd;
}
@@ -294,7 +286,7 @@ class ChangeControl {
try {
switch (perm) {
case READ:
return isVisible(db(), changeData());
return isVisible(changeData());
case ABANDON:
return canAbandon();
case DELETE:

View File

@@ -76,7 +76,6 @@ class DefaultRefFilter {
private final TagCache tagCache;
private final ChangeNotes.Factory changeNotesFactory;
@Nullable private final SearchingChangeCacheImpl changeCache;
private final Provider<ReviewDb> db;
private final GroupCache groupCache;
private final PermissionBackend permissionBackend;
private final ProjectControl projectControl;
@@ -103,7 +102,6 @@ class DefaultRefFilter {
this.tagCache = tagCache;
this.changeNotesFactory = changeNotesFactory;
this.changeCache = changeCache;
this.db = db;
this.groupCache = groupCache;
this.permissionBackend = permissionBackend;
this.skipFullRefEvaluationIfAllRefsAreVisible =
@@ -334,7 +332,7 @@ class DefaultRefFilter {
Project.NameKey project = projectState.getNameKey();
try {
Map<Change.Id, Branch.NameKey> visibleChanges = new HashMap<>();
for (ChangeData cd : changeCache.getChangeData(db.get(), project)) {
for (ChangeData cd : changeCache.getChangeData(project)) {
ChangeNotes notes = changeNotesFactory.createFromIndexedChange(cd.change());
if (!projectState.statePermitsRead()) {
continue;

View File

@@ -34,7 +34,6 @@ import com.google.gerrit.server.permissions.PermissionBackend.ForRef;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.util.MagicBranch;
import com.google.gwtorm.server.OrmException;
import com.google.inject.util.Providers;
import java.util.Collection;
import java.util.EnumSet;
import java.util.List;
@@ -442,7 +441,7 @@ class RefControl {
public ForChange change(ChangeData cd) {
try {
// TODO(hiesel) Force callers to call database() and use db instead of cd.db()
return getProjectControl().controlFor(cd.change()).asForChange(cd, Providers.of(cd.db()));
return getProjectControl().controlFor(cd.change()).asForChange(cd);
} catch (OrmException e) {
return FailedPermissionBackend.change("unavailable", e);
}
@@ -457,12 +456,12 @@ class RefControl {
"expected change in project %s, not %s",
project,
change.getProject());
return getProjectControl().controlFor(notes).asForChange(null, db);
return getProjectControl().controlFor(notes).asForChange(null);
}
@Override
public ForChange indexedChange(ChangeData cd, ChangeNotes notes) {
return getProjectControl().controlFor(notes).asForChange(cd, db);
return getProjectControl().controlFor(notes).asForChange(cd);
}
@Override

View File

@@ -46,7 +46,6 @@ import com.google.gerrit.reviewdb.client.PatchSetApproval;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.client.RobotComment;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.ApprovalsUtil;
import com.google.gerrit.server.ChangeMessagesUtil;
import com.google.gerrit.server.CommentsUtil;
@@ -196,23 +195,22 @@ public class ChangeData {
this.assistedFactory = assistedFactory;
}
public ChangeData create(ReviewDb db, Project.NameKey project, Change.Id id) {
return assistedFactory.create(db, project, id, null, null);
public ChangeData create(Project.NameKey project, Change.Id id) {
return assistedFactory.create(project, id, null, null);
}
public ChangeData create(ReviewDb db, Change change) {
return assistedFactory.create(db, change.getProject(), change.getId(), change, null);
public ChangeData create(Change change) {
return assistedFactory.create(change.getProject(), change.getId(), change, null);
}
public ChangeData create(ReviewDb db, ChangeNotes notes) {
public ChangeData create(ChangeNotes notes) {
return assistedFactory.create(
db, notes.getChange().getProject(), notes.getChangeId(), notes.getChange(), notes);
notes.getChange().getProject(), notes.getChangeId(), notes.getChange(), notes);
}
}
public interface AssistedFactory {
ChangeData create(
ReviewDb db,
Project.NameKey project,
Change.Id id,
@Nullable Change change,
@@ -233,7 +231,7 @@ public class ChangeData {
ChangeData cd =
new ChangeData(
null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, project, id, null, null);
null, project, id, null, null);
cd.currentPatchSet = new PatchSet(new PatchSet.Id(id, currentPatchSetId));
return cd;
}
@@ -256,7 +254,6 @@ public class ChangeData {
private final SubmitRuleEvaluator.Factory submitRuleEvaluatorFactory;
// Required assisted injected fields.
private final ReviewDb db;
private final Project.NameKey project;
private final Change.Id legacyId;
@@ -322,7 +319,6 @@ public class ChangeData {
TrackingFooters trackingFooters,
PureRevert pureRevert,
SubmitRuleEvaluator.Factory submitRuleEvaluatorFactory,
@Assisted ReviewDb db,
@Assisted Project.NameKey project,
@Assisted Change.Id id,
@Assisted @Nullable Change change,
@@ -343,11 +339,6 @@ public class ChangeData {
this.pureRevert = pureRevert;
this.submitRuleEvaluatorFactory = submitRuleEvaluatorFactory;
// May be null in tests when created via createForTest above, in which case lazy-loading will
// intentionally fail with NPE. Still not marked @Nullable in the constructor, to force callers
// using Guice to pass a non-null value.
this.db = db;
this.project = project;
this.legacyId = id;
@@ -367,10 +358,6 @@ public class ChangeData {
return this;
}
public ReviewDb db() {
return db;
}
public AllUsersName getAllUsersNameForIndexing() {
return allUsersName;
}
@@ -536,7 +523,7 @@ public class ChangeData {
try {
currentApprovals =
ImmutableList.copyOf(
approvalsUtil.byPatchSet(db, notes(), c.currentPatchSetId(), null, null));
approvalsUtil.byPatchSet(notes(), c.currentPatchSetId(), null, null));
} catch (OrmException e) {
if (e.getCause() instanceof NoSuchChangeException) {
currentApprovals = Collections.emptyList();

View File

@@ -51,7 +51,7 @@ public class ConflictsPredicate {
ChangeData cd;
List<String> files;
try {
cd = args.changeDataFactory.create(args.db.get(), c);
cd = args.changeDataFactory.create(c);
files = cd.currentFilePaths();
} catch (IOException e) {
throw new OrmException(e);

View File

@@ -33,7 +33,6 @@ 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.client.RefNames;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.index.change.ChangeIndexCollection;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gwtorm.server.OrmException;
@@ -168,11 +167,10 @@ public class InternalChangeQuery extends InternalQuery<ChangeData> {
}
public Iterable<ChangeData> byCommitsOnBranchNotMerged(
Repository repo, ReviewDb db, Branch.NameKey branch, Collection<String> hashes)
Repository repo, Branch.NameKey branch, Collection<String> hashes)
throws OrmException, IOException {
return byCommitsOnBranchNotMerged(
repo,
db,
branch,
hashes,
// Account for all commit predicates plus ref, project, status.
@@ -181,20 +179,16 @@ public class InternalChangeQuery extends InternalQuery<ChangeData> {
@VisibleForTesting
Iterable<ChangeData> byCommitsOnBranchNotMerged(
Repository repo,
ReviewDb db,
Branch.NameKey branch,
Collection<String> hashes,
int indexLimit)
Repository repo, Branch.NameKey branch, Collection<String> hashes, int indexLimit)
throws OrmException, IOException {
if (hashes.size() > indexLimit) {
return byCommitsOnBranchNotMergedFromDatabase(repo, db, branch, hashes);
return byCommitsOnBranchNotMergedFromDatabase(repo, branch, hashes);
}
return byCommitsOnBranchNotMergedFromIndex(branch, hashes);
}
private Iterable<ChangeData> byCommitsOnBranchNotMergedFromDatabase(
Repository repo, ReviewDb db, Branch.NameKey branch, Collection<String> hashes)
Repository repo, Branch.NameKey branch, Collection<String> hashes)
throws OrmException, IOException {
Set<Change.Id> changeIds = Sets.newHashSetWithExpectedSize(hashes.size());
String lastPrefix = null;
@@ -221,7 +215,7 @@ public class InternalChangeQuery extends InternalQuery<ChangeData> {
Change c = cn.getChange();
return c.getDest().equals(branch) && c.getStatus() != Change.Status.MERGED;
});
return Lists.transform(notes, n -> changeDataFactory.create(db, n));
return Lists.transform(notes, n -> changeDataFactory.create(n));
}
private Iterable<ChangeData> byCommitsOnBranchNotMergedFromIndex(

View File

@@ -242,7 +242,7 @@ public class OutputStreamQuery {
ChangeData d, Map<Project.NameKey, Repository> repos, Map<Project.NameKey, RevWalk> revWalks)
throws OrmException, IOException {
LabelTypes labelTypes = d.getLabelTypes();
ChangeAttribute c = eventFactory.asChangeAttribute(db, d.change(), d.notes());
ChangeAttribute c = eventFactory.asChangeAttribute(d.change(), d.notes());
eventFactory.extend(c, d.change());
if (!trackingFooters.isEmpty()) {

View File

@@ -196,7 +196,7 @@ public class DeleteDraftComments
result.change =
changeJsonFactory
.create(ListChangesOption.SKIP_MERGEABLE)
.format(changeDataFactory.create(ctx.getDb(), ctx.getNotes()));
.format(changeDataFactory.create(ctx.getNotes()));
result.deleted = comments.build();
}
return dirty;

View File

@@ -178,12 +178,7 @@ public class DeleteVote extends RetryingRestModifyView<VoteResource, DeleteVoteI
for (PatchSetApproval a :
approvalsUtil.byPatchSetUser(
ctx.getDb(),
ctx.getNotes(),
psId,
accountId,
ctx.getRevWalk(),
ctx.getRepoView().getConfig())) {
ctx.getNotes(), psId, accountId, ctx.getRevWalk(), ctx.getRepoView().getConfig())) {
if (labelTypes.byLabel(a.getLabelId()) == null) {
continue; // Ignore undefined labels.
} else if (!a.getLabel().equals(label)) {

View File

@@ -17,7 +17,6 @@ package com.google.gerrit.server.restapi.change;
import com.google.gerrit.extensions.common.Input;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.index.change.ChangeIndexer;
import com.google.gerrit.server.permissions.GlobalPermission;
@@ -28,25 +27,17 @@ import com.google.gerrit.server.update.RetryHelper;
import com.google.gerrit.server.update.RetryingRestModifyView;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.io.IOException;
@Singleton
public class Index extends RetryingRestModifyView<ChangeResource, Input, Response<?>> {
private final Provider<ReviewDb> db;
private final PermissionBackend permissionBackend;
private final ChangeIndexer indexer;
@Inject
Index(
Provider<ReviewDb> db,
RetryHelper retryHelper,
PermissionBackend permissionBackend,
ChangeIndexer indexer) {
Index(RetryHelper retryHelper, PermissionBackend permissionBackend, ChangeIndexer indexer) {
super(retryHelper);
this.db = db;
this.permissionBackend = permissionBackend;
this.indexer = indexer;
}
@@ -56,7 +47,7 @@ public class Index extends RetryingRestModifyView<ChangeResource, Input, Respons
BatchUpdate.Factory updateFactory, ChangeResource rsrc, Input input)
throws IOException, AuthException, OrmException, PermissionBackendException {
permissionBackend.currentUser().check(GlobalPermission.MAINTAIN_SERVER);
indexer.index(db.get(), rsrc.getChange());
indexer.index(rsrc.getChange());
return Response.none();
}
}

View File

@@ -17,7 +17,6 @@ package com.google.gerrit.server.restapi.change;
import com.google.gerrit.extensions.common.CommentInfo;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.CommentsUtil;
import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.permissions.PermissionBackendException;
@@ -31,18 +30,15 @@ import java.util.Map;
@Singleton
public class ListChangeComments implements RestReadView<ChangeResource> {
private final Provider<ReviewDb> db;
private final ChangeData.Factory changeDataFactory;
private final Provider<CommentJson> commentJson;
private final CommentsUtil commentsUtil;
@Inject
ListChangeComments(
Provider<ReviewDb> db,
ChangeData.Factory changeDataFactory,
Provider<CommentJson> commentJson,
CommentsUtil commentsUtil) {
this.db = db;
this.changeDataFactory = changeDataFactory;
this.commentJson = commentJson;
this.commentsUtil = commentsUtil;
@@ -51,7 +47,7 @@ public class ListChangeComments implements RestReadView<ChangeResource> {
@Override
public Map<String, List<CommentInfo>> apply(ChangeResource rsrc)
throws AuthException, OrmException, PermissionBackendException {
ChangeData cd = changeDataFactory.create(db.get(), rsrc.getNotes());
ChangeData cd = changeDataFactory.create(rsrc.getNotes());
return commentJson
.get()
.setFillAccounts(true)

View File

@@ -18,7 +18,6 @@ import com.google.gerrit.extensions.common.CommentInfo;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.reviewdb.client.Comment;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.CommentsUtil;
import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.permissions.PermissionBackendException;
@@ -32,18 +31,15 @@ import java.util.Map;
@Singleton
public class ListChangeDrafts implements RestReadView<ChangeResource> {
private final Provider<ReviewDb> db;
private final ChangeData.Factory changeDataFactory;
private final Provider<CommentJson> commentJson;
private final CommentsUtil commentsUtil;
@Inject
ListChangeDrafts(
Provider<ReviewDb> db,
ChangeData.Factory changeDataFactory,
Provider<CommentJson> commentJson,
CommentsUtil commentsUtil) {
this.db = db;
this.changeDataFactory = changeDataFactory;
this.commentJson = commentJson;
this.commentsUtil = commentsUtil;
@@ -55,7 +51,7 @@ public class ListChangeDrafts implements RestReadView<ChangeResource> {
if (!rsrc.getUser().isIdentifiedUser()) {
throw new AuthException("Authentication required");
}
ChangeData cd = changeDataFactory.create(db.get(), rsrc.getNotes());
ChangeData cd = changeDataFactory.create(rsrc.getNotes());
List<Comment> drafts =
commentsUtil.draftByChangeAuthor(cd.notes(), rsrc.getUser().getAccountId());
return commentJson

View File

@@ -17,7 +17,6 @@ package com.google.gerrit.server.restapi.change;
import com.google.gerrit.extensions.common.RobotCommentInfo;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.CommentsUtil;
import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.permissions.PermissionBackendException;
@@ -29,18 +28,15 @@ import java.util.List;
import java.util.Map;
public class ListChangeRobotComments implements RestReadView<ChangeResource> {
private final Provider<ReviewDb> db;
private final ChangeData.Factory changeDataFactory;
private final Provider<CommentJson> commentJson;
private final CommentsUtil commentsUtil;
@Inject
ListChangeRobotComments(
Provider<ReviewDb> db,
ChangeData.Factory changeDataFactory,
Provider<CommentJson> commentJson,
CommentsUtil commentsUtil) {
this.db = db;
this.changeDataFactory = changeDataFactory;
this.commentJson = commentJson;
this.commentsUtil = commentsUtil;
@@ -49,7 +45,7 @@ public class ListChangeRobotComments implements RestReadView<ChangeResource> {
@Override
public Map<String, List<RobotCommentInfo>> apply(ChangeResource rsrc)
throws AuthException, OrmException, PermissionBackendException {
ChangeData cd = changeDataFactory.create(db.get(), rsrc.getNotes());
ChangeData cd = changeDataFactory.create(rsrc.getNotes());
return commentJson
.get()
.setFillAccounts(true)

View File

@@ -20,14 +20,12 @@ import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.webui.UiAction;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.StarredChangesUtil;
import com.google.gerrit.server.StarredChangesUtil.IllegalLabelException;
import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
@Singleton
@@ -35,16 +33,11 @@ public class MarkAsReviewed
implements RestModifyView<ChangeResource, Input>, UiAction<ChangeResource> {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final Provider<ReviewDb> dbProvider;
private final ChangeData.Factory changeDataFactory;
private final StarredChangesUtil stars;
@Inject
MarkAsReviewed(
Provider<ReviewDb> dbProvider,
ChangeData.Factory changeDataFactory,
StarredChangesUtil stars) {
this.dbProvider = dbProvider;
MarkAsReviewed(ChangeData.Factory changeDataFactory, StarredChangesUtil stars) {
this.changeDataFactory = changeDataFactory;
this.stars = stars;
}
@@ -67,7 +60,7 @@ public class MarkAsReviewed
private boolean isReviewed(ChangeResource rsrc) {
try {
return changeDataFactory
.create(dbProvider.get(), rsrc.getNotes())
.create(rsrc.getNotes())
.isReviewedBy(rsrc.getUser().asIdentifiedUser().getAccountId());
} catch (OrmException e) {
logger.atSevere().withCause(e).log("failed to check if change is reviewed");

View File

@@ -19,14 +19,12 @@ import com.google.gerrit.extensions.common.Input;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.webui.UiAction;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.StarredChangesUtil;
import com.google.gerrit.server.StarredChangesUtil.IllegalLabelException;
import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
@Singleton
@@ -34,16 +32,11 @@ public class MarkAsUnreviewed
implements RestModifyView<ChangeResource, Input>, UiAction<ChangeResource> {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final Provider<ReviewDb> dbProvider;
private final ChangeData.Factory changeDataFactory;
private final StarredChangesUtil stars;
@Inject
MarkAsUnreviewed(
Provider<ReviewDb> dbProvider,
ChangeData.Factory changeDataFactory,
StarredChangesUtil stars) {
this.dbProvider = dbProvider;
MarkAsUnreviewed(ChangeData.Factory changeDataFactory, StarredChangesUtil stars) {
this.changeDataFactory = changeDataFactory;
this.stars = stars;
}
@@ -66,7 +59,7 @@ public class MarkAsUnreviewed
private boolean isReviewed(ChangeResource rsrc) {
try {
return changeDataFactory
.create(dbProvider.get(), rsrc.getNotes())
.create(rsrc.getNotes())
.isReviewedBy(rsrc.getUser().asIdentifiedUser().getAccountId());
} catch (OrmException e) {
logger.atSevere().withCause(e).log("failed to check if change is reviewed");

View File

@@ -110,7 +110,7 @@ public class Mergeable implements RestReadView<RevisionResource> {
return result;
}
ChangeData cd = changeDataFactory.create(db.get(), resource.getNotes());
ChangeData cd = changeDataFactory.create(resource.getNotes());
result.submitType = getSubmitType(cd);
try (Repository git = gitManager.openRepository(change.getProject())) {

View File

@@ -268,7 +268,7 @@ public class Move extends RetryingRestModifyView<ChangeResource, MoveInput, Chan
List<PatchSetApproval> approvals = new ArrayList<>();
for (PatchSetApproval psa :
approvalsUtil.byPatchSet(
ctx.getDb(), ctx.getNotes(), psId, ctx.getRevWalk(), ctx.getRepoView().getConfig())) {
ctx.getNotes(), psId, ctx.getRevWalk(), ctx.getRepoView().getConfig())) {
ProjectState projectState = projectCache.checkedGet(project);
LabelType type = projectState.getLabelTypes(ctx.getNotes()).byLabel(psa.getLabelId());
// Only keep veto votes, defined as votes where:

View File

@@ -380,8 +380,7 @@ public class PostReview
bu.execute();
// Re-read change to take into account results of the update.
ChangeData cd =
changeDataFactory.create(db.get(), revision.getProject(), revision.getChange().getId());
ChangeData cd = changeDataFactory.create(revision.getProject(), revision.getChange().getId());
for (ReviewerAddition reviewerResult : reviewerResults) {
reviewerResult.gatherResults(cd);
}
@@ -1146,7 +1145,7 @@ public class PostReview
if (ctx.getAccountId().equals(ctx.getChange().getOwner())) {
return true;
}
ChangeData cd = changeDataFactory.create(db.get(), ctx.getNotes());
ChangeData cd = changeDataFactory.create(ctx.getNotes());
ReviewerSet reviewers = cd.reviewers();
if (reviewers.byState(REVIEWER).contains(ctx.getAccountId())) {
return true;
@@ -1357,7 +1356,6 @@ public class PostReview
for (PatchSetApproval a :
approvalsUtil.byPatchSetUser(
ctx.getDb(),
ctx.getNotes(),
psId,
user.getAccountId(),

View File

@@ -82,8 +82,7 @@ public class PostReviewers
}
// Re-read change to take into account results of the update.
addition.gatherResults(
changeDataFactory.create(dbProvider.get(), rsrc.getProject(), rsrc.getId()));
addition.gatherResults(changeDataFactory.create(rsrc.getProject(), rsrc.getId()));
return addition.result;
}
}

View File

@@ -323,7 +323,7 @@ public class Submit
}
ReviewDb db = dbProvider.get();
ChangeData cd = changeDataFactory.create(db, resource.getNotes());
ChangeData cd = changeDataFactory.create(resource.getNotes());
try {
MergeOp.checkSubmitRule(cd, false);
} catch (ResourceConflictException e) {

View File

@@ -25,7 +25,6 @@ import com.google.gerrit.extensions.common.TestSubmitRuleInput.Filters;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.account.AccountLoader;
import com.google.gerrit.server.change.RevisionResource;
import com.google.gerrit.server.permissions.PermissionBackendException;
@@ -38,13 +37,11 @@ import com.google.gerrit.server.rules.PrologRule;
import com.google.gerrit.server.rules.RulesCache;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.util.LinkedHashMap;
import java.util.List;
import org.kohsuke.args4j.Option;
public class TestSubmitRule implements RestModifyView<RevisionResource, TestSubmitRuleInput> {
private final Provider<ReviewDb> db;
private final ChangeData.Factory changeDataFactory;
private final RulesCache rules;
private final AccountLoader.Factory accountInfoFactory;
@@ -57,14 +54,12 @@ public class TestSubmitRule implements RestModifyView<RevisionResource, TestSubm
@Inject
TestSubmitRule(
Provider<ReviewDb> db,
ChangeData.Factory changeDataFactory,
RulesCache rules,
AccountLoader.Factory infoFactory,
ProjectCache projectCache,
DefaultSubmitRule defaultSubmitRule,
PrologRule prologRule) {
this.db = db;
this.changeDataFactory = changeDataFactory;
this.rules = rules;
this.accountInfoFactory = infoFactory;
@@ -95,7 +90,7 @@ public class TestSubmitRule implements RestModifyView<RevisionResource, TestSubm
if (projectState == null) {
throw new BadRequestException("project not found");
}
ChangeData cd = changeDataFactory.create(db.get(), rsrc.getNotes());
ChangeData cd = changeDataFactory.create(rsrc.getNotes());
List<SubmitRecord> records;
if (projectState.hasPrologRules() || input.rule != null) {
records = ImmutableList.copyOf(prologRule.evaluate(cd, opts));

View File

@@ -23,7 +23,6 @@ import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.change.RevisionResource;
import com.google.gerrit.server.project.SubmitRuleEvaluator;
import com.google.gerrit.server.project.SubmitRuleOptions;
@@ -31,11 +30,9 @@ import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.rules.RulesCache;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import org.kohsuke.args4j.Option;
public class TestSubmitType implements RestModifyView<RevisionResource, TestSubmitRuleInput> {
private final Provider<ReviewDb> db;
private final ChangeData.Factory changeDataFactory;
private final RulesCache rules;
private final SubmitRuleEvaluator.Factory submitRuleEvaluatorFactory;
@@ -45,11 +42,9 @@ public class TestSubmitType implements RestModifyView<RevisionResource, TestSubm
@Inject
TestSubmitType(
Provider<ReviewDb> db,
ChangeData.Factory changeDataFactory,
RulesCache rules,
SubmitRuleEvaluator.Factory submitRuleEvaluatorFactory) {
this.db = db;
this.changeDataFactory = changeDataFactory;
this.rules = rules;
this.submitRuleEvaluatorFactory = submitRuleEvaluatorFactory;
@@ -74,7 +69,7 @@ public class TestSubmitType implements RestModifyView<RevisionResource, TestSubm
.build();
SubmitRuleEvaluator evaluator = submitRuleEvaluatorFactory.create(opts);
ChangeData cd = changeDataFactory.create(db.get(), rsrc.getNotes());
ChangeData cd = changeDataFactory.create(rsrc.getNotes());
SubmitTypeRecord rec = evaluator.getSubmitType(cd);
if (rec.status != SubmitTypeRecord.Status.OK) {

View File

@@ -23,13 +23,11 @@ import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.extensions.restapi.RestView;
import com.google.gerrit.reviewdb.client.PatchSetApproval;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.ApprovalsUtil;
import com.google.gerrit.server.change.ReviewerResource;
import com.google.gerrit.server.change.VoteResource;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.util.Map;
import java.util.TreeMap;
@@ -66,12 +64,10 @@ public class Votes implements ChildCollection<ReviewerResource, VoteResource> {
@Singleton
public static class List implements RestReadView<ReviewerResource> {
private final Provider<ReviewDb> db;
private final ApprovalsUtil approvalsUtil;
@Inject
List(Provider<ReviewDb> db, ApprovalsUtil approvalsUtil) {
this.db = db;
List(ApprovalsUtil approvalsUtil) {
this.approvalsUtil = approvalsUtil;
}
@@ -85,7 +81,6 @@ public class Votes implements ChildCollection<ReviewerResource, VoteResource> {
Map<String, Short> votes = new TreeMap<>();
Iterable<PatchSetApproval> byPatchSetUser =
approvalsUtil.byPatchSetUser(
db.get(),
rsrc.getChangeResource().getNotes(),
rsrc.getChange().currentPatchSetId(),
rsrc.getReviewerUser().getAccountId(),

View File

@@ -153,7 +153,7 @@ public class LocalMergeSuperSetComputation implements MergeSuperSetComputation {
walkChangesByHashes(visibleCommits, Collections.emptySet(), or, b);
Set<String> nonVisibleHashes = walkChangesByHashes(nonVisibleCommits, visibleHashes, or, b);
ChangeSet partialSet = byCommitsOnBranchNotMerged(or, db, b, visibleHashes, nonVisibleHashes);
ChangeSet partialSet = byCommitsOnBranchNotMerged(or, b, visibleHashes, nonVisibleHashes);
Iterables.addAll(visibleChanges, partialSet.changes());
Iterables.addAll(nonVisibleChanges, partialSet.nonVisibleChanges());
}
@@ -212,16 +212,12 @@ public class LocalMergeSuperSetComputation implements MergeSuperSetComputation {
}
private ChangeSet byCommitsOnBranchNotMerged(
OpenRepo or,
ReviewDb db,
Branch.NameKey branch,
Set<String> visibleHashes,
Set<String> nonVisibleHashes)
OpenRepo or, Branch.NameKey branch, Set<String> visibleHashes, Set<String> nonVisibleHashes)
throws OrmException, IOException {
List<ChangeData> potentiallyVisibleChanges =
byCommitsOnBranchNotMerged(or, db, branch, visibleHashes);
byCommitsOnBranchNotMerged(or, branch, visibleHashes);
List<ChangeData> invisibleChanges =
new ArrayList<>(byCommitsOnBranchNotMerged(or, db, branch, nonVisibleHashes));
new ArrayList<>(byCommitsOnBranchNotMerged(or, branch, nonVisibleHashes));
List<ChangeData> visibleChanges = new ArrayList<>(potentiallyVisibleChanges.size());
for (ChangeData cd : potentiallyVisibleChanges) {
if (changeIsVisibleToPredicate.match(cd)) {
@@ -234,8 +230,7 @@ public class LocalMergeSuperSetComputation implements MergeSuperSetComputation {
}
private ImmutableList<ChangeData> byCommitsOnBranchNotMerged(
OpenRepo or, ReviewDb db, Branch.NameKey branch, Set<String> hashes)
throws OrmException, IOException {
OpenRepo or, Branch.NameKey branch, Set<String> hashes) throws OrmException, IOException {
if (hashes.isEmpty()) {
return ImmutableList.of();
}
@@ -245,7 +240,7 @@ public class LocalMergeSuperSetComputation implements MergeSuperSetComputation {
}
ImmutableList<ChangeData> result =
ImmutableList.copyOf(
queryProvider.get().byCommitsOnBranchNotMerged(or.repo, db, branch, hashes));
queryProvider.get().byCommitsOnBranchNotMerged(or.repo, branch, hashes));
queryCache.put(k, result);
return result;
}

View File

@@ -542,12 +542,10 @@ public class MergeOp implements AutoCloseable {
private ChangeSet reloadChanges(ChangeSet changeSet) {
List<ChangeData> visible = new ArrayList<>(changeSet.changes().size());
List<ChangeData> nonVisible = new ArrayList<>(changeSet.nonVisibleChanges().size());
changeSet
.changes()
.forEach(c -> visible.add(changeDataFactory.create(db, c.project(), c.getId())));
changeSet.changes().forEach(c -> visible.add(changeDataFactory.create(c.project(), c.getId())));
changeSet
.nonVisibleChanges()
.forEach(c -> nonVisible.add(changeDataFactory.create(db, c.project(), c.getId())));
.forEach(c -> nonVisible.add(changeDataFactory.create(c.project(), c.getId())));
return new ChangeSet(visible, nonVisible);
}

View File

@@ -347,7 +347,7 @@ abstract class SubmitStrategyOp implements BatchUpdateOp {
Map<PatchSetApproval.Key, PatchSetApproval> byKey = new HashMap<>();
for (PatchSetApproval psa :
args.approvalsUtil.byPatchSet(
ctx.getDb(), ctx.getNotes(), psId, ctx.getRevWalk(), ctx.getRepoView().getConfig())) {
ctx.getNotes(), psId, ctx.getRevWalk(), ctx.getRepoView().getConfig())) {
byKey.put(psa.getKey(), psa);
}