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,16 +98,22 @@ class PutTopic implements RestModifyView<ChangeResource, Input>,
} }
cmsg.setMessage(msgBuf.toString()); cmsg.setMessage(msgBuf.toString());
change = db.changes().atomicUpdate(change.getId(), db.changes().beginTransaction(change.getId());
new AtomicUpdate<Change>() { try {
@Override change = db.changes().atomicUpdate(change.getId(),
public Change update(Change change) { new AtomicUpdate<Change>() {
change.setTopic(Strings.emptyToNull(newTopicName)); @Override
ChangeUtil.updated(change); public Change update(Change change) {
return change; change.setTopic(Strings.emptyToNull(newTopicName));
} ChangeUtil.updated(change);
}); return change;
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);