GroupMembershipResolver: Parse filters before iterating through objects

Massive performance improvement! Up to 10x!
This commit is contained in:
Markus Frosch 2018-03-11 13:12:48 +01:00 committed by Thomas Gelf
parent f6cf1a4245
commit 0b7bb123cd
1 changed files with 17 additions and 3 deletions

View File

@ -401,7 +401,7 @@ abstract class GroupMembershipResolver
// TODO: fix this last hard host dependency // TODO: fix this last hard host dependency
$resolver = HostApplyMatches::prepare($object); $resolver = HostApplyMatches::prepare($object);
foreach ($groups as $groupId => $filter) { foreach ($groups as $groupId => $filter) {
if ($resolver->matchesFilter(Filter::fromQueryString($filter))) { if ($resolver->matchesFilter($filter)) {
if (! array_key_exists($groupId, $mappings)) { if (! array_key_exists($groupId, $mappings)) {
$mappings[$groupId] = array(); $mappings[$groupId] = array();
} }
@ -456,7 +456,7 @@ abstract class GroupMembershipResolver
$list[$id] = $group->get('assign_filter'); $list[$id] = $group->get('assign_filter');
} }
return $list; return $this->parseFilters($list);
} }
protected function fetchAppliedGroups() protected function fetchAppliedGroups()
@ -470,7 +470,21 @@ abstract class GroupMembershipResolver
) )
)->where('assign_filter IS NOT NULL'); )->where('assign_filter IS NOT NULL');
return $this->db->fetchPairs($query); return $this->parseFilters($this->db->fetchPairs($query));
}
/**
* Parsing a list of query strings to Filter
*
* @param string[] $list List of query strings
*
* @return Filter[]
*/
protected function parseFilters($list)
{
return array_map(function ($s) {
return Filter::fromQueryString($s);
}, $list);
} }
protected function fetchMissingSingleAssignments() protected function fetchMissingSingleAssignments()