Shard refs/draft-comments/* by change instead of account ID
The motivation is the same as in Ib81d462: scanning the whole refs/draft-comments/* space (with grows without bound) when reindexing a change is potentially too slow. Instead of refs/draft-comments/<sharded account>/<change>, use refs/draft-comments/<sharded change>/<account>. This is mostly straightforward, since there are relatively few places that scan multiple refs; most callers just use the helper method in RefNames. Change-Id: I063e2c496751f637d968c89c1501743074fb9025
This commit is contained in:
committed by
Edwin Kempin
parent
dba0801601
commit
66c76c9d4a
@@ -125,6 +125,21 @@ public final class Account {
|
||||
Integer id = RefNames.parseShardedRefPart(name);
|
||||
return id != null ? new Account.Id(id) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an Account.Id out of the last part of a ref name.
|
||||
* <p>
|
||||
* The input is a ref name of the form {@code ".../1234"}, where the suffix
|
||||
* is a non-sharded account ID. Ref names using a sharded ID should use
|
||||
* {@link #fromRefPart(String)} instead for greater safety.
|
||||
*
|
||||
* @param name ref name
|
||||
* @return account ID, or null if not numeric.
|
||||
*/
|
||||
public static Id fromRefSuffix(String name) {
|
||||
Integer id = RefNames.parseRefSuffix(name);
|
||||
return id != null ? new Account.Id(id) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@Column(id = 1)
|
||||
|
||||
@@ -163,6 +163,11 @@ public final class Change {
|
||||
return new Change.Id(Integer.parseInt(id));
|
||||
}
|
||||
|
||||
public static Id fromRefPart(String ref) {
|
||||
Integer id = RefNames.parseShardedRefPart(ref);
|
||||
return id != null ? new Change.Id(id) : null;
|
||||
}
|
||||
|
||||
static int startIndex(String ref) {
|
||||
if (ref == null || !ref.startsWith(REFS_CHANGES)) {
|
||||
return -1;
|
||||
|
||||
@@ -107,15 +107,15 @@ public class RefNames {
|
||||
return r.toString();
|
||||
}
|
||||
|
||||
public static String refsDraftComments(Account.Id accountId,
|
||||
Change.Id changeId) {
|
||||
StringBuilder r = buildRefsPrefix(REFS_DRAFT_COMMENTS, accountId.get());
|
||||
r.append(changeId.get());
|
||||
public static String refsDraftComments(Change.Id changeId,
|
||||
Account.Id accountId) {
|
||||
StringBuilder r = buildRefsPrefix(REFS_DRAFT_COMMENTS, changeId.get());
|
||||
r.append(accountId.get());
|
||||
return r.toString();
|
||||
}
|
||||
|
||||
public static String refsDraftCommentsPrefix(Account.Id accountId) {
|
||||
return buildRefsPrefix(REFS_DRAFT_COMMENTS, accountId.get()).toString();
|
||||
public static String refsDraftCommentsPrefix(Change.Id changeId) {
|
||||
return buildRefsPrefix(REFS_DRAFT_COMMENTS, changeId.get()).toString();
|
||||
}
|
||||
|
||||
public static String refsStarredChanges(Change.Id changeId,
|
||||
@@ -217,6 +217,26 @@ public class RefNames {
|
||||
return id;
|
||||
}
|
||||
|
||||
static Integer parseRefSuffix(String name) {
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
int i = name.length();
|
||||
while (i > 0) {
|
||||
char c = name.charAt(i - 1);
|
||||
if (c == '/') {
|
||||
break;
|
||||
} else if (!Character.isDigit(c)) {
|
||||
return null;
|
||||
}
|
||||
i--;
|
||||
}
|
||||
if (i == 0) {
|
||||
return null;
|
||||
}
|
||||
return Integer.valueOf(name.substring(i, name.length()));
|
||||
}
|
||||
|
||||
private RefNames() {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user