ObjectApplyMatches: Prepare filters only once

So that it can be re-used on multiple objects during sync.
This commit is contained in:
Markus Frosch 2018-04-12 11:25:58 +02:00 committed by Thomas Gelf
parent 0b7bb123cd
commit c2fcd407cc
1 changed files with 21 additions and 3 deletions

View File

@ -25,16 +25,34 @@ abstract class ObjectApplyMatches
protected static $type;
protected static $preparedFilters = array();
public static function prepare(IcingaObject $object)
{
return new static($object);
}
/**
* Prepare a Filter with fixed columns, and store the result
*
* @param Filter $filter
*
* @return Filter
*/
protected static function getPreparedFilter(Filter $filter)
{
$hash = spl_object_hash($filter);
if (! array_key_exists($hash, self::$preparedFilters)) {
$filter = clone($filter);
static::fixFilterColumns($filter);
self::$preparedFilters[$hash] = $filter;
}
return self::$preparedFilters[$hash];
}
public function matchesFilter(Filter $filter)
{
$filter = clone($filter);
static::fixFilterColumns($filter);
return $filter->matches($this->flatObject);
return static::getPreparedFilter($filter)->matches($this->flatObject);
}
/**