Shard refs/starred-changes refs by change ID instead of account ID

If the ref is sharded by change ID, the lookup by change ID is
cheaper. This is because now we can list all refs that start with
refs/starred-changes/ plus sharded change ID and looking up refs with
a prefix that end on '/' is optimized in jgit.

Finding all changes that were starred by a user gets more expensive
since now we need to scan the complete refs/starred-changes/ namespace
for this.

The ref format is changed, because we plan to store the users that
have starred a change in the change index, and this means that we need
to look them up each time a change is reindex. If reindexing a change
would require a complete scan over the refs/starred-changes/ namespace
this would result in performance issues.

On the other hand looking up the changes that were starred by a user
can be done via the change index so that we don't need to scan the
refs/starred-changes/ namespace in this case either.

Change-Id: Ib81d46283035ef753d35fbc78684ded9f074bd1f
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2016-04-15 16:34:33 +02:00
parent 82d3bfa84c
commit dfe73dc408
3 changed files with 31 additions and 30 deletions

View File

@@ -95,37 +95,36 @@ public class RefNames {
public static String refsDraftComments(Account.Id accountId,
Change.Id changeId) {
StringBuilder r = buildRefsPrefix(REFS_DRAFT_COMMENTS, accountId);
StringBuilder r = buildRefsPrefix(REFS_DRAFT_COMMENTS, accountId.get());
r.append(changeId.get());
return r.toString();
}
public static String refsDraftCommentsPrefix(Account.Id accountId) {
return buildRefsPrefix(REFS_DRAFT_COMMENTS, accountId).toString();
return buildRefsPrefix(REFS_DRAFT_COMMENTS, accountId.get()).toString();
}
public static String refsStarredChanges(Account.Id accountId,
Change.Id changeId) {
StringBuilder r = buildRefsPrefix(REFS_STARRED_CHANGES, accountId);
r.append(changeId.get());
public static String refsStarredChanges(Change.Id changeId,
Account.Id accountId) {
StringBuilder r = buildRefsPrefix(REFS_STARRED_CHANGES, changeId.get());
r.append(accountId.get());
return r.toString();
}
public static String refsStarredChangesPrefix(Account.Id accountId) {
return buildRefsPrefix(REFS_STARRED_CHANGES, accountId).toString();
public static String refsStarredChangesPrefix(Change.Id changeId) {
return buildRefsPrefix(REFS_STARRED_CHANGES, changeId.get()).toString();
}
private static StringBuilder buildRefsPrefix(String prefix,
Account.Id accountId) {
private static StringBuilder buildRefsPrefix(String prefix, int id) {
StringBuilder r = new StringBuilder();
r.append(prefix);
int n = accountId.get() % 100;
int n = id % 100;
if (n < 10) {
r.append('0');
}
r.append(n);
r.append('/');
r.append(accountId.get());
r.append(id);
r.append('/');
return r;
}