Use the GroupIncludeCache whenever possible
Change-Id: Ic4867ea0cbba572ef0ae5800daadf46bb5b9557e
This commit is contained in:
@@ -36,6 +36,7 @@ public class GroupDetailFactory implements Callable<GroupDetail> {
|
|||||||
private final ReviewDb db;
|
private final ReviewDb db;
|
||||||
private final GroupControl.Factory groupControl;
|
private final GroupControl.Factory groupControl;
|
||||||
private final Groups groups;
|
private final Groups groups;
|
||||||
|
private final GroupIncludeCache groupIncludeCache;
|
||||||
|
|
||||||
private final AccountGroup.UUID groupUuid;
|
private final AccountGroup.UUID groupUuid;
|
||||||
private GroupControl control;
|
private GroupControl control;
|
||||||
@@ -45,10 +46,12 @@ public class GroupDetailFactory implements Callable<GroupDetail> {
|
|||||||
ReviewDb db,
|
ReviewDb db,
|
||||||
GroupControl.Factory groupControl,
|
GroupControl.Factory groupControl,
|
||||||
Groups groups,
|
Groups groups,
|
||||||
|
GroupIncludeCache groupIncludeCache,
|
||||||
@Assisted AccountGroup.UUID groupUuid) {
|
@Assisted AccountGroup.UUID groupUuid) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.groupControl = groupControl;
|
this.groupControl = groupControl;
|
||||||
this.groups = groups;
|
this.groups = groups;
|
||||||
|
this.groupIncludeCache = groupIncludeCache;
|
||||||
|
|
||||||
this.groupUuid = groupUuid;
|
this.groupUuid = groupUuid;
|
||||||
}
|
}
|
||||||
@@ -65,11 +68,11 @@ public class GroupDetailFactory implements Callable<GroupDetail> {
|
|||||||
return groups.getMembers(db, groupUuid).filter(control::canSeeMember).collect(toImmutableSet());
|
return groups.getMembers(db, groupUuid).filter(control::canSeeMember).collect(toImmutableSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImmutableSet<AccountGroup.UUID> loadIncludes() throws OrmException {
|
private ImmutableSet<AccountGroup.UUID> loadIncludes() {
|
||||||
if (!control.canSeeGroup()) {
|
if (!control.canSeeGroup()) {
|
||||||
return ImmutableSet.of();
|
return ImmutableSet.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
return groups.getIncludes(db, groupUuid).collect(toImmutableSet());
|
return ImmutableSet.copyOf(groupIncludeCache.subgroupsOf(groupUuid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,21 +15,19 @@
|
|||||||
package com.google.gerrit.server.group;
|
package com.google.gerrit.server.group;
|
||||||
|
|
||||||
import static com.google.common.base.Strings.nullToEmpty;
|
import static com.google.common.base.Strings.nullToEmpty;
|
||||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||||
import com.google.gerrit.extensions.common.GroupInfo;
|
import com.google.gerrit.extensions.common.GroupInfo;
|
||||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
|
||||||
import com.google.gerrit.server.account.GroupControl;
|
import com.google.gerrit.server.account.GroupControl;
|
||||||
|
import com.google.gerrit.server.account.GroupIncludeCache;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -40,19 +38,14 @@ public class ListIncludedGroups implements RestReadView<GroupResource> {
|
|||||||
private static final Logger log = org.slf4j.LoggerFactory.getLogger(ListIncludedGroups.class);
|
private static final Logger log = org.slf4j.LoggerFactory.getLogger(ListIncludedGroups.class);
|
||||||
|
|
||||||
private final GroupControl.Factory controlFactory;
|
private final GroupControl.Factory controlFactory;
|
||||||
private final Provider<ReviewDb> dbProvider;
|
private final GroupIncludeCache groupIncludeCache;
|
||||||
private final Groups groups;
|
|
||||||
private final GroupJson json;
|
private final GroupJson json;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ListIncludedGroups(
|
ListIncludedGroups(
|
||||||
GroupControl.Factory controlFactory,
|
GroupControl.Factory controlFactory, GroupIncludeCache groupIncludeCache, GroupJson json) {
|
||||||
Provider<ReviewDb> dbProvider,
|
|
||||||
Groups groups,
|
|
||||||
GroupJson json) {
|
|
||||||
this.controlFactory = controlFactory;
|
this.controlFactory = controlFactory;
|
||||||
this.dbProvider = dbProvider;
|
this.groupIncludeCache = groupIncludeCache;
|
||||||
this.groups = groups;
|
|
||||||
this.json = json;
|
this.json = json;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,10 +57,8 @@ public class ListIncludedGroups implements RestReadView<GroupResource> {
|
|||||||
|
|
||||||
boolean ownerOfParent = rsrc.getControl().isOwner();
|
boolean ownerOfParent = rsrc.getControl().isOwner();
|
||||||
List<GroupInfo> included = new ArrayList<>();
|
List<GroupInfo> included = new ArrayList<>();
|
||||||
ImmutableList<AccountGroup.UUID> includedGroupUuids =
|
Collection<AccountGroup.UUID> includedGroupUuids =
|
||||||
groups
|
groupIncludeCache.subgroupsOf(rsrc.toAccountGroup().getGroupUUID());
|
||||||
.getIncludes(dbProvider.get(), rsrc.toAccountGroup().getGroupUUID())
|
|
||||||
.collect(toImmutableList());
|
|
||||||
for (AccountGroup.UUID includedGroupUuid : includedGroupUuids) {
|
for (AccountGroup.UUID includedGroupUuid : includedGroupUuids) {
|
||||||
try {
|
try {
|
||||||
GroupControl i = controlFactory.controlFor(includedGroupUuid);
|
GroupControl i = controlFactory.controlFor(includedGroupUuid);
|
||||||
|
|||||||
Reference in New Issue
Block a user