SystemGroupBackend: Compute names of system groups only once

Change-Id: I18ebbef9e6b0fa6fd1828a3682b23697d7b91190
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2017-01-19 13:41:07 +01:00
parent a03f240d5b
commit 96a4ba47d1
2 changed files with 5 additions and 9 deletions

View File

@@ -169,8 +169,7 @@ public class CreateGroup implements RestModifyView<TopLevelResource, GroupInput>
throws OrmException, ResourceConflictException, IOException {
// Do not allow creating groups with the same name as system groups
List<String> sysGroupNames = SystemGroupBackend.getNames();
for (String name : sysGroupNames) {
for (String name : SystemGroupBackend.getNames()) {
if (name.toLowerCase(Locale.US).equals(
createGroupArgs.getGroupName().toLowerCase(Locale.US))) {
throw new ResourceConflictException("group '" + name

View File

@@ -15,6 +15,7 @@
package com.google.gerrit.server.group;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.stream.Collectors.toSet;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@@ -33,6 +34,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
@@ -96,13 +98,8 @@ public class SystemGroupBackend extends AbstractGroupBackend {
return checkNotNull(uuids.get(uuid), "group %s not found", uuid.get());
}
public static List<String> getNames() {
List<String> names = new ArrayList<>();
for (AccountGroup.UUID uuid : all) {
int c = uuid.get().indexOf(':');
names.add(uuid.get().substring(c + 1).replace('-', ' '));
}
return names;
public static Set<String> getNames() {
return names.values().stream().map(r -> r.getName()).collect(toSet());
}
@Override