Store information about starring changes in notedb
To keep track of a change that is starred by a user we create a refs/starred-changes/YY/XXXX/ZZZZ ref in the All-Users notedb repository, where YY/XXXX is the sharded account ID and ZZZZ is the numeric change ID. The refs/starred-changes/* refs point to empty tree objects since the existence of a ref is enough to know that a change was starred by a user. The ref format is similar to the refs/draft-comments/* refs that store draft comments in the All-Users notedb repository, but it uses '/' instead of '-' to separate the sharded account ID from the change ID. This is because we need to find all refs that start with the prefix refs/starred-changes/YY/XXXX/ and RefDirectory in jgit has explicit optimizations for the case when the prefix ends with '/' and we want to take advantage of this. Change-Id: I033b35a05749929c9c0ea778075c4a1085c5bf2a Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -43,6 +43,9 @@ public class RefNames {
|
||||
/** Draft inline comments of a user on a change */
|
||||
public static final String REFS_DRAFT_COMMENTS = "refs/draft-comments/";
|
||||
|
||||
/** A change starred by a user */
|
||||
public static final String REFS_STARRED_CHANGES = "refs/starred-changes/";
|
||||
|
||||
/**
|
||||
* Prefix applied to merge commit base nodes.
|
||||
* <p>
|
||||
@@ -113,6 +116,32 @@ public class RefNames {
|
||||
return r;
|
||||
}
|
||||
|
||||
public static String refsStarredChanges(Account.Id accountId,
|
||||
Change.Id changeId) {
|
||||
StringBuilder r = buildRefsPrefix(REFS_STARRED_CHANGES, accountId);
|
||||
r.append(changeId.get());
|
||||
return r.toString();
|
||||
}
|
||||
|
||||
public static String refsStarredChangesPrefix(Account.Id accountId) {
|
||||
return buildRefsPrefix(REFS_STARRED_CHANGES, accountId).toString();
|
||||
}
|
||||
|
||||
private static StringBuilder buildRefsPrefix(String prefix,
|
||||
Account.Id accountId) {
|
||||
StringBuilder r = new StringBuilder();
|
||||
r.append(prefix);
|
||||
int n = accountId.get() % 100;
|
||||
if (n < 10) {
|
||||
r.append('0');
|
||||
}
|
||||
r.append(n);
|
||||
r.append('/');
|
||||
r.append(accountId.get());
|
||||
r.append('/');
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns reference for this change edit with sharded user and change number:
|
||||
* refs/users/UU/UUUU/edit-CCCC/P.
|
||||
|
Reference in New Issue
Block a user