GroupMembershipResolver: do not fill objects...

...cache when not being told so. Also, fix query order/operator to ensure an
AND is being used.
This commit is contained in:
Thomas Gelf 2017-08-21 08:12:04 +02:00
parent 9adeb65f0c
commit 0bd2a328ed
1 changed files with 17 additions and 3 deletions

View File

@ -381,7 +381,13 @@ abstract class GroupMembershipResolver
{
$mappings = array();
foreach ($this->getObjects() as $object) {
if ($this->objects === null) {
$objects = $this->fetchAllObjects();
} else {
$objects = & $this->objects;
}
foreach ($objects as $object) {
// TODO: fix this last hard host dependency
$resolver = HostApplyMatches::prepare($object);
foreach ($groups as $groupId => $filter) {
@ -449,11 +455,14 @@ abstract class GroupMembershipResolver
array("gor" => $this->getResolvedTableName()),
"go.${type}_id = gor.${type}_id AND go.${type}group_id = gor.${type}group_id",
array()
)->where("gor.${type}_id IS NULL");
);
$this->addMembershipWhere($query, "go.${type}_id", $this->objects);
$this->addMembershipWhere($query, "go.${type}group_id", $this->groups);
// Order matters, this must be AND:
$query->where("gor.${type}_id IS NULL");
return $this->db->fetchAll($query);
}
@ -498,12 +507,17 @@ abstract class GroupMembershipResolver
protected function getObjects()
{
if ($this->objects === null) {
$this->objects = IcingaObject::loadAllByType($this->getType(), $this->connection);
$this->objects = $this->fetchAllObjects();
}
return $this->objects;
}
protected function fetchAllObjects()
{
return IcingaObject::loadAllByType($this->getType(), $this->connection);
}
protected function assertBeenLoadedFromDb(IcingaObject $object)
{
if (! ctype_digit($object->get('id'))) {