Use transactions to handle comments when possible

If the database supports transactions (see gwtorm, not all do)
try to perform some update operations as a single transaction on
the change. This may allow the database to batch together any
record updates, saving some time.

Change-Id: I5af9efe3a541d83515109e3bf9a3497b3d8127de
This commit is contained in:
Shawn O. Pearce
2011-10-28 15:57:51 -07:00
parent d3743450a2
commit 77c684b417
3 changed files with 88 additions and 61 deletions

View File

@@ -116,18 +116,25 @@ public class PublishComments implements Callable<VoidResult> {
}
drafts = drafts();
publishDrafts();
db.changes().beginTransaction(changeId);
try {
publishDrafts();
final boolean isCurrent = patchSetId.equals(change.currentPatchSetId());
if (isCurrent && change.getStatus().isOpen()) {
publishApprovals(ctl);
} else if (! approvals.isEmpty()) {
throw new InvalidChangeOperationException("Change is closed");
} else {
publishMessageOnly();
final boolean isCurrent = patchSetId.equals(change.currentPatchSetId());
if (isCurrent && change.getStatus().isOpen()) {
publishApprovals(ctl);
} else if (!approvals.isEmpty()) {
throw new InvalidChangeOperationException("Change is closed");
} else {
publishMessageOnly();
}
touchChange();
db.commit();
} finally {
db.rollback();
}
touchChange();
email();
fireHook();
return VoidResult.INSTANCE;