From 0bd2a328ed68d3a471c0e5995d09dc2e18ff3100 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 21 Aug 2017 08:12:04 +0200 Subject: [PATCH] GroupMembershipResolver: do not fill objects... ...cache when not being told so. Also, fix query order/operator to ensure an AND is being used. --- .../Objects/GroupMembershipResolver.php | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/library/Director/Objects/GroupMembershipResolver.php b/library/Director/Objects/GroupMembershipResolver.php index d8fed591..cf9c8666 100644 --- a/library/Director/Objects/GroupMembershipResolver.php +++ b/library/Director/Objects/GroupMembershipResolver.php @@ -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'))) {