Optimize edit handling in VisibleRefFilter
Checking each ref through the RefNames.isRefsEditOf is still several percent of the total garbage created by a busy Gerrit server filtering references for clients... most of which don't have pending edits. Rewrite this handling to reduce the StringBuilder allocations so that the user prefix is built once and reused over the refs. Fix the TODO about filtering edits to visible changes; we have the Set<Change.Id> readily available and can parse the Change.Id out of the edit ref name to test in the set once we know the ref is owned by the current user. Rework much of the VisibleRefFilter logic to simplify the !showMetadata case to short-circuit through the loop more quickly. This speeds up advertisment generation for pushes by a very small amount, but also simplifies every single branch so its worth the code churn either way. Change-Id: I15d97ec7783e8bd6c7a042a020cdcf4352273cab
This commit is contained in:
@@ -164,29 +164,17 @@ public class RefNames {
|
||||
* @return reference prefix for this change edit
|
||||
*/
|
||||
public static String refsEditPrefix(Account.Id accountId, Change.Id changeId) {
|
||||
return new StringBuilder(refsUsers(accountId))
|
||||
.append('/')
|
||||
.append(EDIT_PREFIX)
|
||||
.append(changeId.get())
|
||||
.append('/')
|
||||
.toString();
|
||||
return refsEditPrefix(accountId) + changeId.get() + '/';
|
||||
}
|
||||
|
||||
public static String refsEditPrefix(Account.Id accountId) {
|
||||
return refsUsers(accountId) + '/' + EDIT_PREFIX;
|
||||
}
|
||||
|
||||
public static boolean isRefsEdit(String ref) {
|
||||
return ref.startsWith(REFS_USERS) && ref.contains(EDIT_PREFIX);
|
||||
}
|
||||
|
||||
public static boolean isRefsEditOf(String ref, Account.Id accountId) {
|
||||
if (accountId == null) {
|
||||
return false;
|
||||
}
|
||||
String prefix = new StringBuilder(refsUsers(accountId))
|
||||
.append('/')
|
||||
.append(EDIT_PREFIX)
|
||||
.toString();
|
||||
return ref.startsWith(prefix);
|
||||
}
|
||||
|
||||
static Integer parseShardedRefPart(String name) {
|
||||
if (name == null) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user