Cache Group Monitors Ids so we don't query the database multiple times for them.

pull/3588/head
Isaac Connor 2022-08-31 18:36:57 +02:00
parent 62a8b72dc4
commit 1038e2d069
1 changed files with 5 additions and 1 deletions

View File

@ -8,6 +8,7 @@ class Group extends ZM_Object {
'Name' => array('type'=>'text','filter_regexp'=>'/[^\w\-\.\(\)\:\/ ]/', 'default'=>'Group'),
'ParentId' => null,
);
protected static $monitor_ids_cache = array();
public static function find( $parameters = array(), $options = array() ) {
return ZM_Object::_find(get_class(), $parameters, $options);
@ -47,7 +48,10 @@ class Group extends ZM_Object {
public function MonitorIds( ) {
if ( ! property_exists($this, 'MonitorIds') ) {
$this->{'MonitorIds'} = dbFetchAll('SELECT `MonitorId` FROM `Groups_Monitors` WHERE `GroupId`=?', 'MonitorId', array($this->{'Id'}));
if (!isset($monitor_ids_cache[$this->{'Id'}])) {
$monitor_ids_cache[$this->{'Id'}] = dbFetchAll('SELECT `MonitorId` FROM `Groups_Monitors` WHERE `GroupId`=?', 'MonitorId', array($this->{'Id'}));
}
$this->{'MonitorIds'} = &$monitor_ids_cache[$this->{'Id'}];
}
return $this->{'MonitorIds'};
}