Perform PutTopic in a database "transaction"

Wrapping both writes into a begin/commit block allows these to
be aggregated in the backend for gerrit-review, slightly reducing
latency for topic changes.

Change-Id: I9849219012d999817e5d719c1d2b04a5cea4d4a9
This commit is contained in:
Shawn Pearce
2013-07-23 12:09:24 -07:00
parent 16b41a3500
commit b406aa68b9

View File

@@ -98,6 +98,8 @@ class PutTopic implements RestModifyView<ChangeResource, Input>,
} }
cmsg.setMessage(msgBuf.toString()); cmsg.setMessage(msgBuf.toString());
db.changes().beginTransaction(change.getId());
try {
change = db.changes().atomicUpdate(change.getId(), change = db.changes().atomicUpdate(change.getId(),
new AtomicUpdate<Change>() { new AtomicUpdate<Change>() {
@Override @Override
@@ -108,6 +110,10 @@ class PutTopic implements RestModifyView<ChangeResource, Input>,
} }
}); });
db.changeMessages().insert(Collections.singleton(cmsg)); db.changeMessages().insert(Collections.singleton(cmsg));
db.commit();
} finally {
db.rollback();
}
indexer.index(change); indexer.index(change);
hooks.doTopicChangedHook(change, currentUser.getAccount(), hooks.doTopicChangedHook(change, currentUser.getAccount(),
oldTopicName, db); oldTopicName, db);