Make refs/draft-comments/ consistent with refs/starred-changes/

refs/starred-changes/ uses '/' to separate the sharded account ID from
the change ID, but refs/draft-comments/ uses '-'. Make the naming
consistent by using '/' in both cases. Using '/' has better
performance when looking up all refs that start with this prefix
because RefDirectory in jgit has explicit optimizations for the case
when the prefix ends with '/'.

Change-Id: Iade2b0d2c54a46318e339dbabffd0c714d864564
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin 2015-11-17 15:18:32 -08:00
parent 17c33ce0ad
commit f67da65ef6
3 changed files with 5 additions and 20 deletions

View File

@ -92,28 +92,13 @@ public class RefNames {
public static String refsDraftComments(Account.Id accountId,
Change.Id changeId) {
StringBuilder r = buildRefsDraftCommentsPrefix(accountId);
StringBuilder r = buildRefsPrefix(REFS_DRAFT_COMMENTS, accountId);
r.append(changeId.get());
return r.toString();
}
public static String refsDraftCommentsPrefix(Account.Id accountId) {
return buildRefsDraftCommentsPrefix(accountId).toString();
}
public static StringBuilder buildRefsDraftCommentsPrefix(
Account.Id accountId) {
StringBuilder r = new StringBuilder();
r.append(REFS_DRAFT_COMMENTS);
int n = accountId.get() % 100;
if (n < 10) {
r.append('0');
}
r.append(n);
r.append('/');
r.append(accountId.get());
r.append('-');
return r;
return buildRefsPrefix(REFS_DRAFT_COMMENTS, accountId).toString();
}
public static String refsStarredChanges(Account.Id accountId,

View File

@ -39,13 +39,13 @@ public class RefNamesTest {
@Test
public void refsDraftComments() throws Exception {
assertThat(RefNames.refsDraftComments(accountId, changeId))
.isEqualTo("refs/draft-comments/23/1011123-67473");
.isEqualTo("refs/draft-comments/23/1011123/67473");
}
@Test
public void refsDraftCommentsPrefix() throws Exception {
assertThat(RefNames.refsDraftCommentsPrefix(accountId))
.isEqualTo("refs/draft-comments/23/1011123-");
.isEqualTo("refs/draft-comments/23/1011123/");
}
@Test

View File

@ -371,7 +371,7 @@ public class PatchLineCommentsUtil {
private Iterable<String> getDraftRefs(final Change.Id changeId)
throws OrmException {
Set<String> refNames = getRefNamesAllUsers(RefNames.REFS_DRAFT_COMMENTS);
final String suffix = "-" + changeId.get();
final String suffix = "/" + changeId.get();
return Iterables.filter(refNames, new Predicate<String>() {
@Override
public boolean apply(String input) {