Avoid unnecessary group visibility checks

The list-groups REST API call checked group visibility even for those
groups which are filtered out. In a system with 10-20K of groups
this can cause 30-60 seconds delay when checking if current user can
see a group.

Avoid unnecessary group visibility checks by moving it towards the end
of the loop. Therefore, group visibility is only checked for those
groups which are not filtered out.

Change-Id: Id5984049d0103fbbf656b704f672f01283844b64
This commit is contained in:
Saša Živkov 2016-11-10 11:19:55 +01:00 committed by David Pursehouse
parent 1d55a32535
commit df0145d52f

@ -322,12 +322,6 @@ public class ListGroups implements RestReadView<TopLevelResource> {
continue;
}
}
if (!isAdmin) {
final GroupControl c = groupControlFactory.controlFor(group);
if (!c.isVisible()) {
continue;
}
}
if (visibleToAll && !group.isVisibleToAll()) {
continue;
}
@ -335,6 +329,12 @@ public class ListGroups implements RestReadView<TopLevelResource> {
&& !groupsToInspect.contains(group.getGroupUUID())) {
continue;
}
if (!isAdmin) {
final GroupControl c = groupControlFactory.controlFor(group);
if (!c.isVisible()) {
continue;
}
}
filteredGroups.add(group);
}
Collections.sort(filteredGroups, new GroupComparator());