Add a short-lived ref cache interface

We already have ChainedReceiveCommands that contains a per-instance
ref cache that guarantees that subsequent reads for a given ref will
be the same, and avoids a few syscalls to boot. Extract an interface
from ChainedReceiveCommands so we can use the caching part without the
commands part.

Use Optional<ObjectId> consistently in the return type, so that
callers do not have to determine whether null or zeroId indicates a
missing ref. Currently they need to expect null for exactRef-style
semantics and zeroId for ReceiveCommand-style semantics, which can be
confusing.

Change-Id: I5e02032d6d406b30a1cc4704808e9b2475e5b417
This commit is contained in:
Dave Borowitz
2016-05-05 14:37:35 -04:00
parent 2b3a69395d
commit a4d86e8f40
10 changed files with 168 additions and 76 deletions

View File

@@ -24,6 +24,7 @@ import com.google.gerrit.reviewdb.client.PatchLineComment;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.client.RevId;
import com.google.gerrit.server.git.RepoRefCache;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.assistedinject.Assisted;
@@ -152,7 +153,8 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
NoteDbChangeState state = NoteDbChangeState.parse(change);
// Only check if this particular user's drafts are up to date, to avoid
// reading unnecessary refs.
if (state == null || !state.areDraftsUpToDate(repo, author)) {
if (state == null
|| !state.areDraftsUpToDate(new RepoRefCache(repo), author)) {
return rebuildAndOpen(repo);
}
}