Avoid opening extra ReviewDb connection in PatchSetInfoFactory

Every caller already had a ReviewDb "handy". Rather than making
a new connection, use the existing one from the caller to read
records about the patch set from the database.

Change-Id: I68de1aa293f81b4318d681851706556bb73a5fd7
This commit is contained in:
Shawn O. Pearce
2011-10-28 15:57:04 -07:00
parent 2d82b4a84e
commit d3743450a2
7 changed files with 8 additions and 18 deletions

View File

@@ -138,7 +138,7 @@ class PatchSetDetailFactory extends Handler<PatchSetDetail> {
detail = new PatchSetDetail();
detail.setPatchSet(patchSet);
detail.setInfo(infoFactory.get(psIdNew));
detail.setInfo(infoFactory.get(db, psIdNew));
detail.setPatches(patches);
final CurrentUser user = control.getCurrentUser();

View File

@@ -83,7 +83,7 @@ final class PatchSetPublishDetailFactory extends Handler<PatchSetPublishDetail>
final Change.Id changeId = patchSetId.getParentKey();
final ChangeControl control = changeControlFactory.validateFor(changeId);
change = control.getChange();
patchSetInfo = infoFactory.get(patchSetId);
patchSetInfo = infoFactory.get(db, patchSetId);
drafts = db.patchComments().draftByPatchSetAuthor(patchSetId, user.getAccountId()).toList();
aic.want(change.getOwner());

View File

@@ -51,7 +51,7 @@ public final class StoredValues {
PatchSetInfoFactory patchInfoFactory =
env.getInjector().getInstance(PatchSetInfoFactory.class);
try {
return patchInfoFactory.get(patchSetId);
return patchInfoFactory.get(REVIEW_DB.get(engine), patchSetId);
} catch (PatchSetInfoNotAvailableException e) {
throw new SystemException(e.getMessage());
}

View File

@@ -1254,7 +1254,7 @@ public class MergeOp {
// Go back to the patch set that was actually merged.
//
try {
c.setCurrentPatchSet(patchSetInfoFactory.get(merged));
c.setCurrentPatchSet(patchSetInfoFactory.get(schema, merged));
} catch (PatchSetInfoNotAvailableException e1) {
log.error("Cannot read merged patch set " + merged, e1);
}

View File

@@ -136,7 +136,7 @@ public abstract class ChangeEmail extends OutgoingEmail {
if (patchSet != null && patchSetInfo == null) {
try {
patchSetInfo = args.patchSetInfoFactory.get(patchSet.getId());
patchSetInfo = args.patchSetInfoFactory.get(args.db.get(), patchSet.getId());
} catch (PatchSetInfoNotAvailableException err) {
patchSetInfo = null;
}

View File

@@ -25,7 +25,6 @@ import com.google.gerrit.reviewdb.UserIdentity;
import com.google.gerrit.server.account.AccountByEmailCache;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -49,15 +48,12 @@ import java.util.Set;
@Singleton
public class PatchSetInfoFactory {
private final GitRepositoryManager repoManager;
private final SchemaFactory<ReviewDb> schemaFactory;
private final AccountByEmailCache byEmailCache;
@Inject
public PatchSetInfoFactory(final GitRepositoryManager grm,
final SchemaFactory<ReviewDb> schemaFactory,
final AccountByEmailCache byEmailCache) {
this.repoManager = grm;
this.schemaFactory = schemaFactory;
this.byEmailCache = byEmailCache;
}
@@ -68,16 +64,13 @@ public class PatchSetInfoFactory {
info.setAuthor(toUserIdentity(src.getAuthorIdent()));
info.setCommitter(toUserIdentity(src.getCommitterIdent()));
info.setRevId(src.getName());
return info;
}
public PatchSetInfo get(PatchSet.Id patchSetId)
throws PatchSetInfoNotAvailableException {
ReviewDb db = null;
public PatchSetInfo get(ReviewDb db, PatchSet.Id patchSetId)
throws PatchSetInfoNotAvailableException {
Repository repo = null;
try {
db = schemaFactory.open();
final PatchSet patchSet = db.patchSets().get(patchSetId);
final Change change = db.changes().get(patchSet.getId().getParentKey());
final Project.NameKey projectKey = change.getProject();
@@ -97,9 +90,6 @@ public class PatchSetInfoFactory {
} catch (IOException e) {
throw new PatchSetInfoNotAvailableException(e);
} finally {
if (db != null) {
db.close();
}
if (repo != null) {
repo.close();
}

View File

@@ -288,7 +288,7 @@ public class PublishComments implements Callable<VoidResult> {
if (message != null) {
final CommentSender cm = commentSenderFactory.create(change);
cm.setFrom(user.getAccountId());
cm.setPatchSet(patchSet, patchSetInfoFactory.get(patchSetId));
cm.setPatchSet(patchSet, patchSetInfoFactory.get(db, patchSetId));
cm.setChangeMessage(message);
cm.setPatchLineComments(drafts);
cm.send();