IcingaObject: loadAllByType should respect PrefetchCache

This commit is contained in:
Markus Frosch 2016-10-31 17:17:56 +01:00
parent 86d2f317ee
commit 672a45b26e
1 changed files with 11 additions and 1 deletions

View File

@ -2101,12 +2101,22 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
public static function loadAllByType($type, Db $db, $query = null, $keyColumn = 'object_name')
{
/** @var DbObject $class */
$class = self::classByType($type);
if (is_array($class::create()->getKeyName())) {
return $class::loadAll($db, $query);
} else {
return $class::loadAll($db, $query, $keyColumn);
if (PrefetchCache::shouldBeUsed() && $query === null && $keyColumn === 'object_name') {
$result = array();
foreach ($class::prefetchAll($db) as $row) {
$result[$row->object_name] = $row;
}
return $result;
}
else {
return $class::loadAll($db, $query, $keyColumn);
}
}
}